X = SQRT(Y)
will assign the square root of Y to X.
In a programming language which supports the SQRT function, such a statement would:
Thus, for example:
and that startingline and WhichWord are parameters.
Now find where the function FindMin is referenced in the mouseup handler of the 'Do it!' button script:
In this statement, current is the number of the current line and whichWord is the number of the word used as the basis of the sort. The values of the parameters current and whichWord are set in the MouseUp handler. When FindMin is referenced in the MouseUp handler, the values contained in these variables are channeled into the function handler through its defined parameters startingline and whichWord. Thus, the values contained in current and whichWord are passed to function FindMin through the parameters startingline and whichWord.
The function FindMin (in the 'Do it!' button script) returns the value associated with the variable where (note the last line of the function definition). What type of value does where contain? If you examine the FindMin script, you will discover that where is assigned a line number, namely the number of the line which has the current minimum value of the word WhichWord. Thus the statement:
in the MouseUp handler assigns the number of the line that contains the minimum (up till now) value of WhichWord to the variable found.
Recall that the logical (or boolean) data values are 'true' and 'false'. It is possible, therefore, to define functions that are of type logical.
In lab exercise 7.2 if Module 4, you are asked to script a function called FormatOK. The function will examine a line of data and make sure it contains four words. If it does, the function will return 'true', otherwise it will return 'false'. Thus FormatOK will be of type logical, and can be included in any boolean or logical expression, for example:
if FormatOK(thisline) then -- process this line of dataFormatOK may be defined as follows:
function FormatOK dataline -- dataline is the parameter if number of words of dataline = 4 then return true else return false end if end FormatOK
We can use FormatOK to check whether a line of 'data' has 4 words, and if it does, then we can process the line of data.
You may now practice using the function. First determine where the FormatOK function should be defined in the No Account stack and define it. Now write statements in some other handlers to test it. All of the button scripts that manipulate the data lines in card field 'data' should have access to this function. Before they manipulate a line of data you can use FormatOK to check that line. For example:
put number of lines of card field data into numlines repeat with count = 1 to numlines put line count of card field data into thisline if not FormatOK(thisline) then answer "Bad data format" with "Okay" else -- process this line of data end if end repeat
Of course, to really test this function, card field 'data' must contain some ill-formatted data lines. Make sure you update card field 'data' with one or more lines that do not contain four words.