Le 16 août 06 à 13:49 Soir, Steven Hedgepeth a écrit:
Dear Anatomically Correct Programming Advice Genius,
Regarding the following code I found in the MenuItemPopUp example:
if CheckBox1.Value then
// Let's display it with an absolute position of 0, 0.
// This is globally absolute, not relative to the window!
returnItem = bar.PopUp( -20, -20 )
else
// Just display as normal
returnItem = bar.PopUp
end
Is the value of CheckBox1 both boolean and integer, i.e., true is
the same as 1 and false is the same as 0?
The value of a checkbox is a boolean, you can't use it as an integer.
You can't write:
dim i As Integer
i=CheckBox1.Value+5
they are not the sane type of data.
Indeed, in binary, 0 means false while 1 means true (while, in
decimal, anything but 0 means true). But, programatically, a boolean
is not an integer.
Saying "If CheckBox1.Value then" is the same as saying "if
CheckBox1.Value=true then".
When an "if" statement is encountered, the code between the "if" and
the "end if" is executed if the expression between the words "if" and
"then" is true.
So:
if CheckBox1.Value=true then 'Is executed when the Checkbox1.value
equals true (when the checkbox is checked).
if CheckBox1.Value then 'Is also executed when the Checkbox1.value is
true (since it is the expression evaluated).
if CheckBox1.Value=false then 'Is executed when the Checkbox1.value
is false.
if not CheckBox1.Value then 'is also executed when the Checkbox1 is
not checked.
The main difference is the timing used.
In "if CheckBox1.Value=true then", the Checkbox1.Value is evaluated
(is it false or true?), next, the "true" value is evaluated the same
way (both side of the equal sign must be evaluated in order to be
compared; it may be something else than "true" or "false"). If the
comparison is true, the block is executed (that's how ifs work).
In "if CheckBox1.Value then", the Checkbox1.Value is evaluated. There
is no further comparison to evaluate, simply the "CheckBox1.Value".
It's faster to evaluate "CheckBox1.Value" than "CheckBox1.Value" and
"true".
This may be complex, I hope I was clear enough.
HTH_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>