ZBasic Language Reference
51
ZBasic Microcontrollers
Sub Main()
Dim b as Byte
' specify the initialization data
Call d1.Source("mydata.txt")
b = d1(2)
End Sub
Only one method of specifying the initialization data can be used for any particular Program Memory data
item. Attempting to specify the initialization data multiple times will result in a compiler error even if the
data supplied in the multiple cases is identical.
2.11 String Types
ZBasic supports several variations of the fundamental type String. You may define a string variable
thus:
Dim msg as String
The amount of space required for this variable definition and the maximum size of the string that it can
represent varies depending compiler command line options and Option Directives. By default, the
maximum string size is 255 characters. See Section 3.27 for more information on the implementation
details of the various string data types.
2.11.1 Bounded Strings
A bounded string is nothing more than a way to specify a string having a maximum length that may be
different than the default string length. A bounded string is defined using the syntax:
{Public | Private | Dim} <name> as [New] BoundedString(<size-expr>)
When defining a bounded string, you replace the <size-expr> with a constant integral expression
specifying the number of bytes to allocate for the strings characters. It is important to be aware that
assigning a string that has more characters than a bounded string variable's capacity will cause locations
following that variable to be overwritten. Therefore, it is imperative that you write your code to explicitly
limit the length of a string assigned to a bounded string variable.
Examples
Const slen as Integer = 7
Dim msg as BoundedString(15)
Dim msg as BoundedString(slen + 2)
The first definition will create a string variable that can hold up to 15 characters; the second will hold 9
characters.
For compatibility with BasicX, the alternate syntax shown below is also supported. New applications
should use the definition syntax given above since it allows the use of an expression to specify the length.
{Public | Private | Dim} <name> as New BoundedString_<length>
2.11.2 Fixed-Length Strings
For compatibility with BasicX, ZBasic supports fixed-length strings. These are similar to bounded strings
but with two important distinctions. Firstly, the string size is constant and equal to the specified fixed size.
|