Quick Tip: Change a Button's Text and Action

by Barry Rochford

One of my Clients manages Food Service Operations in Small Hospitals & Long Term Care Facilities in three States. Each Installation has two to three Cash Registers – Whoops, Point of Sale Terminals. They asked me to come up with a Cashier Sub-system. They also have Charge Sales and Payments Received.

ChangeButtonText.gif

Fig 1 displays the Register Entry Form. Most amounts are calculated, with the others entered by the Cashier using the POS Terminal Tape totals.

My Form has a Conditional Object , cond1. The top object, the default "Register Recap" , is shown . Underneath are "Charges" and "Payments". I have a SAVE Button that saves the record and prints a Register Recap, but if there were Charge Sales, they must be entered, if there were Payments Received, they must be also be entered. (Button1 is "SAVE", button2 is "Close" and button3 is "New Record").

Rather than adding 2 more buttons, and depending on the Cashier to remember to enter the proper Data, I decided to change the Text (and Actions) of the SAVE Button (Button1). Using Xbasic Explorer, I saw that Button1 has a Text Property. This was going to be easy.

Here is the Script for Button1's OnPush Event (only relevant portions are shown)

' Barry Rochford – modified 2-2-99
' Button1 OnPush Event
if button1.text="Enter Charges" then 
	c_object="Charges" 
	'changes the Conditional object to Charges
	cond1.refresh()
	button3.disable() 'disables New Record Button
 	if reg_total->recd_onacct >.00 then 
		'ck for Charges AND Event Payments
		button1.text="Enter Events"
	else
		button1.text="SAVE" 
	end if
	button1.refresh() 'refreshes the button
	end 
end if
if button1.text="Enter Events" then
	c_object="Pmts" 
	'changes the Conditional object to Pmts
	button1.text=("SAVE")
	cond1.refresh()
	button1.refresh()
	button3.disable() 
	end
else
	c_object=""
	cond1.refresh()
end if
' ***** Application specific coding not shown *****
button3.enable() 'Enable New Record Button
end

Now I had one Button that took different actions depending on the contents of the button text. The operator is lead to the proper Entry Form without having to make decisions.

Barry is an Alpha Developer living close to Newtown, PA. He can be reached at brochford@enter.net

7/4/99

Don't forget, we need your feedback to make this site better!

Return to home