Button Scripts
Space is a scarce resource on every layout. By using a button’s text property to show what it has done we can save space on the form as well as make the interface behave in a way that users experience as responsive since it tells them the current state of the system and how to change it. Turning the button into its own label also ensures that users are never confused about where to look for information.
by Bill Hanigsberg
One place this works quite well is on buttons that are used for changing the index. The button text can be changed to show the current index selection each time the button is pressed. Shown below is a simple case where a table has only two indexes from which users can choose. They are “lname” and “fiche” (French for file, or personal ID). The button merely finds which index is current and switches to the other.
The only new wrinkle is that the button text is updated to reflect the current selection.
''Xbasic
' Code attached to a button on a form
' Button text displays the active index
DIM tbl as p
DIM ndx_ptr as p
DIM ndx_tag as c
DIM vTxt as c
'--- Editor's note: The above DIM statements are optional.
tbl=table.current() '--- get pointer to the form's table
ndx_ptr=tbl.index_primary_get() '--- pointer to current index
ndx_tag=ndx_ptr.name_get() '--- name of the current index
'--- Button toggles selection between two indexes and
'--- displays name of the active index
IF ndx_tag = "lname"
parentform.index_set( "Fiche" )
vTxt = "Current order is Fiche. Press to change"
ELSE
parentform.index_set( "lname" )
vTxt = "Current order is Last name. Press to change"
END IF
this.text = vTxt '--- the "this" alias refers to the button
END