into processing the information gathered.
Concept- If we want to count out 5 apples, we don't call the
first apple zero. However, computers like to start counting at zero.
(We don't). Bacon has an option that specifies to start counts with
1 instead of zero. "OPTION BASE 1". Put that near the top of the
program. See the BaCon doc for further information.
The ENTRY widget allows the user to type in some piece
of information. Their name for example. This is how we'll
set up an info label and an ENTRY widget.
Code: Select all
'--- Customer info
Customer_label_ = MARK("We'll call you when order is ready!", 380, 30)
PROPERTY(Customer_label_, "xalign", 0.5)
ATTACH(Mainwin_, Customer_label_, 10, 220)
Customer_name_ = ENTRY(Customer_directions$, 380, 30)
ATTACH(Mainwin_, Customer_name_, 10, 246)
the "Cancel" button. We need a CALLBACK to trigger a FUNCTION
when the "Place-Order" button is clicked.
Code: Select all
Place_order_ = BUTTON("Place-Order", 100, 28)
ATTACH(Mainwin_, Place_order_, 170, 365)
CALLBACK(Place_order_, PLACE_ORDER)
We'll only do minimal amount of error checking.
GRAB$(widget_) gets the text, if any, that is in the ENTRY widget.
The double set of double quotes stands for a "null" string (ie. nothing).
If ENTRY is blank, we'll just wait until the customer
is ready to let us know their name The CHOP$ command removes any
leading or trailing spaces or tabs.
Code: Select all
' ------------------
FUNCTION PLACE_ORDER
' ------------------
Customer_name$ = GRAB$(Customer_name_)
Customer_name$ = CHOP$(Customer_name$)
IF Customer_name$ = "" THEN
RETURN FALSE
END IF
END FUNCTION
entered their first and last names. To do this, we use the SPLIT
command. We use the space character as the seperator (if there is one).
ex. SPLIT String_to_split$ BY character_to_split_on TO an_array_name$ SIZE how_many_names.
After SPLIT seperates the string into individual smaller chunks (array), it sets
the "how_many_names" variable to the number of smaller chunks. If the customer
entered their first and last name, how_many_names will be set to 2. If there is only
one name, SPLIT is happy setting how_many to one. By the way, if we hadn't used
the "OPTION BASE 1" mentioned earlier, we'd be working with 0 and 1. One meaning
that there are actually two items. (That can get confusing quick.) Any way,
using SPLIT we can make sure we have a single name and that's all the error
checking we'll do on that item.
Code: Select all
' ------------------
FUNCTION PLACE_ORDER
' ------------------
Customer_name$ = GRAB$(Customer_name_)
IF Customer_name$ = "" THEN
RETURN FALSE
END IF
SPLIT Customer_name$ BY " " TO Array$ SIZE How_many_names
Customer_name$ = Array$[ How_many_names ]
END FUNCTION
Grab the drink order with Drink$ = GRAB$(Drink_combo_) .
The radio buttons for slice thickness take a little more work. We have
to check each one to see which is selected. It will be TRUE if it is selected,
otherwise FALSE. This is a simple IF/THEN test so we can use the shortened IF/THEN syntax.
Now check if they're ordering eggs, and if so grab that information.
The call to our SHOW_ORDER function opens a message box so that the customer
can confirm the order is correct.
Code: Select all
' ------------------
FUNCTION PLACE_ORDER
' ------------------
Customer_name$ = GRAB$(Customer_name_)
IF Customer_name$ = "" THEN
RETURN FALSE
END IF
SPLIT Customer_name$ BY " " TO Array$ SIZE How_many_names
Customer_name$ = Array$[ How_many_names ]
Drink$ = GRAB$(Drink_combo_)
IF GET(Slice_size_1_) THEN Slice_thickness$ = "Thin"
IF GET(Slice_size_2_) THEN Slice_thickness$ = "Medium"
IF GET(Slice_size_3_) THEN Slice_thickness$ = "Thick"
Eggs_cooked$ = ""
How_many_eggs$ = ""
IF GET(Eggs_or_not_) THEN
Eggs_cooked$ = GRAB$(Eggs_list_)
How_many_eggs$ = STR$( GET(How_many_eggs_))
END IF
SHOW_ORDER : 'Show Msgdialog, Confirm order
RETURN TRUE
END FUNCTION
source code for location and details.
Code: Select all
'--- This initializes the MSGDIALOG, but doesn't display it yet
Order_window_ = MSGDIALOG("Confirm Order", 300, 220, 4, 5)
'--- This "shows" the MSGDIALOG when the "Place-Order" button is clicked
CALLBACK(Place_order_, PLACE_ORDER)
'--- This "hides" the MSGDIALOG when the "dialog" button is clicked
CALLBACK(Order_window_, ORDER_CLOSE)
Code: Select all
' ------------------
SUB SHOW_ORDER
' ------------------
Tmp$ = CONCAT$("Hello ", Customer_name$, NL$, NL$)
Tmp$ = CONCAT$(Tmp$, "Please click OK if order is correct", NL$, NL$)
Tmp$ = CONCAT$(Tmp$, "Drink - ", Drink$, NL$)
Tmp$ = CONCAT$(Tmp$, "Bacon - ", Slice_thickness$, NL$)
IF GET(Eggs_or_not_) THEN
Tmp$ = CONCAT$(Tmp$, How_many_eggs$, " Egg(s), ", Eggs_cooked$, NL$)
ELSE
Tmp$ = CONCAT$(Tmp$, "No Eggs", NL$)
END IF
TEXT(Order_window_, Tmp$)
SHOW(Order_window_)
END SUB
' ------------------
SUB ORDER_CLOSE(NUMBER Dialog_, int Button_)
' ------------------
HIDE(Dialog_)
END SUB
using BaCon and HUG.
I added a few other goodies in the source to discover, but you should be able
to figure them out
Happy Crankin'
rod