February 15, 200322 yr Can anyone tell me if it is possible to script a button such that it changes the value in a field each time it is switched (like a logic switch)? What I want is for the field value to change from 0 to 1 (if it is 0) and change back from 1 to 0 the next time it is clicked. I know I can do this with two buttons for each choice, but I have to need a lot of them, and it really clutters up my layout. Thanks,
February 15, 200322 yr Script the button with If "yourfieldvalue" = 1 setfield "yourfieldvalue", 0 End If If "yourfieldvalue" = 0 setfield "yourfieldvalue", 1 End if
February 15, 200322 yr Hi John, I think there may be simpler ways to handle your situation, but without knowing the purpose or a bit more, we can't give you other ideas. Are you using this switch to track whether another field value has been changed? Or simply to select/de-select a record? For instance, if the switch should change if a value in another field is changed or modified, you could use a calc, unstored num (and identify the fact that a field has changed, via several possibly functions, including Status(CurrentRecordModificationCount) or if ModificationDate has changed, etc. If you simply want a switch, you might consider creating a value list called Switch (which I stole from CobaltSky). Here is the explanation of the process: An example of a value list that might get used more than once would be a value list called 'Switch' with the value set as 1, which can be used to drive a checkbox interface (so that if the box is checked the field holds a 1 and if not it is null). With a 'Switch' value list, you only need one of them, because the same value list can be attached to many fields on a layout - all the checkboxes in fact. So when a user brings up a layout, they may be looking at a dozen instances of the 'Switch' value list in a variety of states (i.e. on or off) scattered throughout the data. Another example would be a value list for a questionnaire based on the Likert Scale method (where each record has a number of questions which are answered as: Passionately Agree Agree Undecided Disagree Violently Object Again, the same value list might be applied to all twenty fields of the questionaire. Very ecomonical! Then there's all the generic value lists that have things like Small Medium Large Extra Large with Fries and a Coke You can also attach the script directly to the field instead of having to select a button. Anyway, I think we could offer better suggestions if we had a bit more information as to what you wish to accomplish! LaRetta
February 15, 200322 yr Author Hi Ugo - I tried this script: If ["Area 1 =1"] Set Field ["Area 1=0"] End If If ["Area 1=0"] Set Field ["Area 1=1"] End If When I click the button nothing happens. If I click in the field and then click the button, it becomes a 0. Clicking the button again still gets me no change. Can you tell me what I'm not understanding here, please? Thanks, John
February 15, 200322 yr Author Hi LaRetta - My problem is this: 1. I have a series of city names that can be chosen by a Volunteer at Trinity Hospice Care. The Volunteer may chose one or more of these cities in which to provide hospice care. 2. What I want to end up with is a field that is a concatenation of the cities chosen. 3. I figured that, if I could assign a button that would switch on or off for each of the City choices, I could then compute a field that would contain just those choices (e.g. choosing Redondo Beach and Torrance would yield "Redondo Beach, Torrance, while choosing Hermosa Beach, Torrance and Palos Verdes would yield Hermosa Beach, Torrance, Palos Verdes). Maybe I am making this too complicated - can you suggest a better approach? Thanks, John
February 15, 200322 yr Hi John! Well, I'm no expert, but I would suggest you check out a demo file called List Compiler by CobaltSky ListCompiler. What this will do is, as each city is selected, it will be added to the list. Then you'd just need a calc to display the results in a Case statement. If you use a switch field (which would apply to each record), you can end up with duplicate cities selected by accident. How are you displaying the cities? Are you finding all unique and then displaying on a list? LaRetta
February 15, 200322 yr Sorry for that. You need to insert stop script. If Value = 1 Set field Value, 0 Stop script End if If Value = 0 Set field Value, 1 Stop script End if
February 15, 200322 yr I felt idiot some time ago with this. Duplicate your field in the layout. Set format for first field as a checkbox format Set format for second to plain text. Go and see what happens.
February 15, 200322 yr Author Well, now i'm really confused! Ugo - tried your changes using "Halt Script" - no change - tried using "Exit Script" still no change (this ocurred with both a plain text field and a checkbox field. LaRetta - downloaded that file, but it does not work. When I selected another ingredient the results field cleared itself permanently. Regards, John
February 15, 200322 yr Author Ugo - Perfect! Thanks mon ami. PS What kind of cars do race? I was involved in sports car racing as an official here in Southern California for about 25 years, and was the Chief observer for the final F-1 race at Long Beach in 1983.
February 15, 200322 yr Glad it workded.: Well for the rest, it's not me, it's just Gilles Villeneuve. But in 1983... For so many italian (was born there just one mile from Ferrari's circuit), he still remains a Myth...
February 15, 200322 yr Hi John, Here is one without the halt scripts. If [ YourField = 1 ] Set Field [ YourField , YourField = 0 ] Else Set Field [ YourField , YourField + 1 ] End If HTH Lee I removed the go to layout, you don't need it.
February 15, 200322 yr Set field ["yourfield","abs(yourfield-1)"] THE oneliner for toggle between 0 and 1 Harryk
February 16, 200322 yr Oh so sorry John! If it cleared the field when you tried to use it, you must be using vs. 5.0!! List Compiler requires FMPv5.5 or above because ListCompiler takes advantage of the GetField() function. I should have asked you which version you were using, sorry about that. LaRetta
February 16, 200322 yr Author Thanks to all of you, your suggestions and ideas were great. I can't believe you all paid so much attention to my little problem. Thanks especially to LoRetta and Ugo (who gave me the best clues and solutions). You guys are wonderful! John
Create an account or sign in to comment