ZBasic Language Reference
28
ZX Microcontroller Family
For advanced users, the task stack may also be specified by giving its address explicitly. This topic is
discussed in section 3.5.1, Advanced Multi-tasking Options.
2.5.4 Console.Write and Console.WriteLine Statements
These statements (with a syntax more akin to object-oriented methods) are similar to Debug.Print but
they are limited to displaying one string at a time. They are supported for compatibility with Visual Basic.
The syntax of the statements is:
Console.Write( <string-expression> )
Console.WriteLine( <string-expression> )
The difference between these two statements is that the latter also outputs a carriage return/line feed
following the string while the former does not.
Examples
Dim i as Integer
Dim s as String
Console.WriteLine(CStr(i))
Console.WriteLine("i = " & CStr(i))
Console.Write("s = ")
Console.WriteLine(s)
Console.WriteLine("")
This sequence of statements is written to produce exactly the same result as the sequence of
Debug.Print statements above. Note how the string concatenation operation is used in the second
Console.WriteLine() invocation to produce a single string. In the final example, an empty string is
output followed by a carriage return/line feed.
Note that there are counterparts to these statements called Console.Read and Console.ReadLine that
allow you to retrieve data from the Com1 serial port. However, these are technically functions (since they
both return a value) and are therefore not described here. See the ZBasic System Library Reference
manual for information on these functions.
2.5.5 Debug.Print Statement
One technique for debugging a program is called print statement debugging. The idea is that to
determine how your program is executing you insert statements into the program that display the values
of important variables or simply display a distinctive message so that you know what the program is
doing. Debug.Print is a special statement intended just for this purpose. The syntax is:
Debug.Print [<string-list>][;]
The <string-list> element represents zero or more string expressions separated from one another
by a semicolon. Each of the string expressions is evaluated in turn, from left to right, and the string result
of each is output to Com1. If the optional trailing semicolon is omitted, a carriage return/line feed will also
be output so that the next time something is output to Com1 it will appear on a new line. If you dont want
the subsequent output to be on a new line, simply add the semicolon at the end of the list. This is often
done when you need to compute several different values to output. You can use a separate
Debug.Print statement for each value and keep them all on the same output line by ending all but the
last with a semicolon. It is permitted, syntactically, to specify an empty string list but still include the
trailing semicolon. However, this construction does nothing.