Hello Bacon (World)
Posted: Tue 09 Aug 2011, 22:15
For both of you who are following along, I hope you're
trying out these examples. Make changes, move things around,
add to, etc.
A "CONST" (constant) is a variable that is not going to change value
during the course of the program run. I want a carriage return
ie. NewLine in the text so that the text for the CHECKbox
isn't stretched out. We'll use the CONCAT$ command to
concatinate (string together) three string$. "NL$" is
a reserved word for the "New Line" character. CONST doesn't
really buy us much in a program of this size. But in larger
programs it'll help us keep track of variable names we're using
and save memory space. (This is my opinion/thought on CONST).
Since the CONST declares a variable of fixed length, it is static.
The program sets it up and leaves it alone. A variable length
variable can be dynamic, changing length, memory location and
how much memory it occupies. That means the program has to spend
some amount of resources keeping track of it, moving it around,
making sure there is memory available. etc. So I suggest using
CONST where appropriate. For GLOBAL variables, in addition to
helping you keep track of the variables you're using, it gives
the compiler a "heads up" on the variables to come.
(Or I may just be full of it ) At any rate, we'll use this
CONST in our program. Look at the screen shot to see the effects of NL$.
Introducing three more widgets AND going to add a tad bit of logic in to boot.
We'll add a section for ordering Eggs, putting a FRAME around it.
Nothing new here:
The first widget is the CHECKbox.
Next up is a LIST widget. Items are added to the LIST widget
in the same way we added items to the COMBO widget; with
the TEXT method. I deliberately added more items to the
list than will fit in the LIST window. This to show that
the list window will automatically add a scrool bar. If
an item in the list is too wide to fit the window, a
horizontal scrool bar will be added. Note the DISABLE
method is used, the list is "grayed out" and not accessable.
(We'll do the same for the egg count).
The SPIN widget is just an up/down counter. It's set up
like this:
Handle_ = SPIN( xsize, ysize, start_count, end_count, step)
Throw in a label so the user knows what the count is for.
This SPINner allows the user to pick from 1 to 4 eggs.
Now we'll add in some logic. If the CHECK box is blank, then
the user doesn't get to make selections about the eggs.
ie. DISABLE'd. If the box is checked, we need to ENABLE the
egg selection widgets. We'll do the actual enable-ing with a
call to a SUBroutine; get to that in a moment.
There are two parts to the logic here. First, watch the
CHECK box for a change. Second, do something if the CHECK box
status changes. We'll set up a CALLBACK function to watch for
an "event" (in this case anything) to happen to the CHECK box.
We gave the CHECK box the widget handle "Eggs_or_not_". And
we'll write a subroutine named "ENABLE_EGGS" to execute when
an event occurs to "Eggs_or_not_".
About the IF/THEN construct. In simplest form-
The "this_is_true" just needs to evaluate to a non zero
result. In our case, GET(.....) gets the value of the CHECK box
widget. "0" if not checked, "1" if checked. So if our CHECK box
is checked, GET(Eggs_or_not_) evaluates to "1" ie TRUE, and the
following commands are executed. Otherwise it must be FALSE, so
execute the commands after the "ELSE" statement. For more in-depth
info on IF/THEN, Google-it.
Check out the whole program to see how the widgets are used, and the
CALLBACK and SUB routine are setup.
rod
(how did I get the text at the top bigger and thicker ?)
trying out these examples. Make changes, move things around,
add to, etc.
A "CONST" (constant) is a variable that is not going to change value
during the course of the program run. I want a carriage return
ie. NewLine in the text so that the text for the CHECKbox
isn't stretched out. We'll use the CONCAT$ command to
concatinate (string together) three string$. "NL$" is
a reserved word for the "New Line" character. CONST doesn't
really buy us much in a program of this size. But in larger
programs it'll help us keep track of variable names we're using
and save memory space. (This is my opinion/thought on CONST).
Since the CONST declares a variable of fixed length, it is static.
The program sets it up and leaves it alone. A variable length
variable can be dynamic, changing length, memory location and
how much memory it occupies. That means the program has to spend
some amount of resources keeping track of it, moving it around,
making sure there is memory available. etc. So I suggest using
CONST where appropriate. For GLOBAL variables, in addition to
helping you keep track of the variables you're using, it gives
the compiler a "heads up" on the variables to come.
(Or I may just be full of it ) At any rate, we'll use this
CONST in our program. Look at the screen shot to see the effects of NL$.
Code: Select all
CONST Egg_checkbox$ = CONCAT$("Check if you", NL$, " want eggs")
We'll add a section for ordering Eggs, putting a FRAME around it.
Nothing new here:
Code: Select all
'--- Add FRAME for eggs
Eggs_frame_ = FRAME(380, 130)
TEXT(Eggs_frame_, " How about those Eggs ")
ATTACH(Mainwin_, Eggs_frame_, 10, 85)
Code: Select all
'--- CHECK box for eggs
Eggs_or_not_ = CHECK(Egg_checkbox$, 100, 45)
ATTACH(Mainwin_, Eggs_or_not_, 20, 130)
in the same way we added items to the COMBO widget; with
the TEXT method. I deliberately added more items to the
list than will fit in the LIST window. This to show that
the list window will automatically add a scrool bar. If
an item in the list is too wide to fit the window, a
horizontal scrool bar will be added. Note the DISABLE
method is used, the list is "grayed out" and not accessable.
(We'll do the same for the egg count).
Code: Select all
'--- Add a LIST widget for cooking eggs
Eggs_list_ = LIST(120, 100)
TEXT(Eggs_list_, "Sunny Side Up")
TEXT(Eggs_list_, "Over Easy")
TEXT(Eggs_list_, "Scrambled")
TEXT(Eggs_list_, "Poached")
TEXT(Eggs_list_, "Runny")
TEXT(Eggs_list_, "Hard Boiled")
ATTACH(Mainwin_, Eggs_list_, 150, 105)
DISABLE(Eggs_list_)
like this:
Handle_ = SPIN( xsize, ysize, start_count, end_count, step)
Throw in a label so the user knows what the count is for.
This SPINner allows the user to pick from 1 to 4 eggs.
Code: Select all
'--- Label/MARK for egg count
Tmp$ = CONCAT$("How Many", NL$, " Eggs")
How_many_label_ = MARK(Tmp$, 75, 40)
ATTACH(Mainwin_, How_many_label_, 300, 120)
'--- Add SPINner widget for how many eggs
How_many_eggs_ = SPIN(40, 26, 1, 4, 1)
ATTACH(Mainwin_, How_many_eggs_, 320, 160)
DISABLE(How_many_eggs_)
SET(How_many_eggs_, 2)
the user doesn't get to make selections about the eggs.
ie. DISABLE'd. If the box is checked, we need to ENABLE the
egg selection widgets. We'll do the actual enable-ing with a
call to a SUBroutine; get to that in a moment.
There are two parts to the logic here. First, watch the
CHECK box for a change. Second, do something if the CHECK box
status changes. We'll set up a CALLBACK function to watch for
an "event" (in this case anything) to happen to the CHECK box.
We gave the CHECK box the widget handle "Eggs_or_not_". And
we'll write a subroutine named "ENABLE_EGGS" to execute when
an event occurs to "Eggs_or_not_".
Code: Select all
CALLBACK(Eggs_or_not_, ENABLE_EGGS)
Code: Select all
IF this_is_true THEN
do_this
END IF
result. In our case, GET(.....) gets the value of the CHECK box
widget. "0" if not checked, "1" if checked. So if our CHECK box
is checked, GET(Eggs_or_not_) evaluates to "1" ie TRUE, and the
following commands are executed. Otherwise it must be FALSE, so
execute the commands after the "ELSE" statement. For more in-depth
info on IF/THEN, Google-it.
Code: Select all
' ------------------
SUB ENABLE_EGGS
' ------------------
IF GET(Eggs_or_not_) THEN
ENABLE(Eggs_list_)
ENABLE(How_many_eggs_)
ELSE
DISABLE(Eggs_list_)
DISABLE(How_many_eggs_)
END IF
END SUB
CALLBACK and SUB routine are setup.
rod
(how did I get the text at the top bigger and thicker ?)