You can't have button icons switch by script or calculation. What you could do is:
1. create two copies of the button
2. assign a script parameter to each which will be used to set the globals variable
3. set each button to hide according to the state of the global variable
4. alter your script to respond to these new conditions
If you can't work this out for yourself, take a look at my version of your file, as attached.
SortSwitchDEMO.fmp12.zip 70.3 K
You said you were using a button bar; but actually, you were not. Attached is a copy of your file that does use a button bar, and uses hide object when calculation to control which segement displays.
Also, your script does not really provide an Unsort option, did you want to include one?
SortMODBFR.fmp12.zip 70.6 K
Your attached file is enough...thank you so much!
Hope this is not too much...I am trying to copy your technique file, but I dont know how to implement with another field.
Sort.fmp12.zip 70.7 K
Thank you for the reply. I already fixed the script that you pointed out but when I click for example my material code button, the two button for sorting for material are showing, same thing happen when I click my material name button. How can I fix it?
I recommend you figure that out for yourself.
I've been playing for this for the whole day, but I cant figure it out.
any help is appreciated.
If you can't get Bruce's method to work, here's another route (probably one of several) ...
- Create a global number field to act as a Boolean flag - sorted or unsorted (here, g_flagSorted)
- Create a text calculation field in the table where it's appropriate:
SortStateLabel = If ( yourTable::g_flagSorted, "(sorted)¶UNSORT"; "(unsorted)¶SORT")
- Put one button on your layout and make its label something like <<yourTable::SortStateLabel>>
- Create a script for the button to run:
> Check that you are in Browse mode (see Get(WindowMode))
> If yourTable::g_flagSorted > 0, Unsort the records and set g_flagSorted to 0
> Else, Sort the records and set g_flagSorted to 1
You may be able to do without the global flag altogether by using Get(SortState) in your label calculation.
1 of 1 people found this helpful
Rather than two copies of the button, button bars are excellent for this usage. they can have "Hide object when" independently set. While it looks like two buttons in Layout mode, the width of the space is the same with one button in Browse mode while the other is hidden. This what is in Bruce's demo 'SortMODBFR.fmp12.zip'!!
If you look at the Button Bar in Layout mode, you can:
1 click the 'bar' and look a the properties in INSPECTOR
2. click each 'button' and look at the properties in INSPECTOR
3. when you double-click (or choose 'Button Bar Setup' from the Format menu), you get the dialog for setting the 'buttons'. each button can have different scripts assigned (or the same script with different parameters passed)
Also there is a script step that may be beneficial: