24 of 172
ZBasic Language Reference 17 ZX Microcontroller Family Private Const Pi as Single = 3.14159 Const TwoPi as Single = Pi * 2.0 You may also use certain System Library functions in the constant’s value expression. The restriction is that the expression must be able to be evaluated at compile time. Private Const Pi as Single = ACos(-1.0) Private Const InitialValue as Single = Sin(Pi / 2.0) The definition of the value of pi in the manner shown in the first example is useful because it results in the maximum accuracy of the constant value. String constants are sometimes useful as well. Public Const VersionNum as String = "V1.0" Public Const VersionDate as String = "Oct 2005" Public Const VersionStr as String = VersionNum & " " & VersionDate Public Const VersionDateUC as String = UCase(VersionDate) You may define multiple constants of the same or different types on the same line. Const c1 as Integer = 7, c2 as Single = 3e10 BasicX Compatibility Note In BasicX mode, UnsignedInteger, UnsignedLong and String constants are not supported. Also, constant expressions cannot utilize built-in functions. Defining Variables To define a variable at the module level (as opposed to within a subroutine or function, described later) the syntax is: {Public | Private | Dim} <name> As <type> Dim has exactly the same effect as Private, i.e., the variable will only be directly accessible to code within the module. Examples Dim ival as Integer, pulseCount as Byte Private busy as Boolean Dim msg as String The first example above shows two different variables being defined on the same line. The initial value of a variable depends on its type and how it is defined. See Section 2.12 for information on variable initialization. Defining Arrays of Variables Variables which hold a single value like those discussed above are called scalar variables. ZBasic also supports arrays of variables. An array of a fundamental type may be defined using the syntax: