By Matt Neuburg
Cover | Table of Contents | Colophon
beep msgBox "Sorry, this application doesn't do much!"
beep msgBox "Sorry, this application doesn't do much!"
beep msgBox "Sorry, this application doesn't do much!" // error: Unexpected token
beep msgBox // error: Unexpected end of line "Sorry, this application doesn't do much!" // another error: Statement expected
msgBox
command requires more information—okay, says REALbasic, I
should put up a dialog, but what should the dialog say? That
information belongs to the = operator. An
operator
is a symbol, as in arithmetic, used to combine two values or to
change a single value. The name goes on the left side of the
= operator, the value on the right. For example,
we might say:
myBirthYear = 1954 thisYear = 2001
myBirthYear ends up having associated with it the
numeric value 1954, and the name
thisYear ends up having associated with it with
the numeric value 2001. Such a command, one whose
main verb is the = operator, is called an
assignment.
myAge = thisYear - myBirthYear
myAge ends up having associated with it the number
47.
Sub
HandlerName()
// ... commands go here ...
End Sub
Function
HandlerName() As
ReturnType
// ... commands go here ...
End Function
true or
false, and a condition poses a question that
REALbasic can answer by evaluating it as true or
false. For example, in this line of code:
if x = 3 then
x
=
3 is not an assignment; it's a boolean
expression. This boolean expression is being used as a condition, and
we're asking REALbasic to test the condition by evaluating the
boolean expression. In this instance, REALbasic is to examine the
value of x and see if it actually is
3. If so, the condition is
true; if not, the condition is
false. Your intuitions about fundamental logic and
about how to use concepts such as "if" will work
perfectly well here. (The formal explanation of booleans appears in
Chapter 5.)
myStrings, then myStrings(1)
would be a string value, myStrings(2) would be
another string value, myStrings(3) would be yet
another string value, and so forth.
myStrings is an array of 100 strings, it is a lot
easier to specify the desired string by one name and an index number
than to have to maintain 100 names. But also, a notion such as
"the next string" is expressible by a simple arithmetic
process—incrementing the index—and thus it becomes very
easy to perform such a task as visiting every string. So, for
example, to set each of our 100 strings to
"hello", one can say:
for i = 1 to 100
myStrings(i) = "hello"
next
|
1
|
2
|
3
|
4
|
|
5
|
6
|
7
|
8
|
sortedArray, and that we wish to know whether it
contains a given string, whatStr. We specify that
a function findSorted should accept
whatStr as a parameter and return an integer that
is the index of the matching string in
sortedArray, or 0 if no match
is found. (We presume, for simplicity, that
sortedArray is available without having to be
passed as a parameter; for example, it could be a property.) Clearly
we could just examine every item of sortedArray in
numerical order, until either we find a match or we deduce that
whatStr is absent:
Function findSorted(whatStr as string) As integer
dim i, u as integer
u = ubound(sortedArray)
for i = 1 to u
if sortedArray(i) = whatStr then
return i
elseIf sortedArray(i) > whatStr then
return 0
end
next
return 0
End Function
//
'
Rem
(short for "remark")
myWindow.turnBlue
myWindow.turnBlue
nil; otherwise, a variable goes out of existence
automatically when its subroutine terminates execution, and a
property goes out of existence automatically when the instance that
owns it goes out of existence. An instance is destroyed when its
reference count drops to zero. (Actually, the programmer can get
access to an instance's reference count, through the built-in
Runtime object; this is discussed in Chapter 8.)