44 of 158
38 Example If (GetPin(20) = 1) And _ (GetPin(12) = 0) Then Call PutPin(5, 0) End If While the line continuation capability allows you to create statements that span multiple lines, it is sometimes convenient to place multiple statements on one line. In ZBasic, as in many other Basic dialects, you may accomplish this by using a colon to separate each pair of statements on the line. Example Dim i as Integer Dim j as Integer, k as Byte i = 0 : j = 1 : k = 2 2.9 Persistent Variables You may define variables that are stored in the processor’s internal EEPROM, referred to in this document as Persistent Memory. It is called persistent because the values that you store there are retained even if the system is powered down or reset. This characteristic makes persistent variables useful for storing configuration information for your application and other similar information that your application needs to be preserved. A persistent variable is defined at the module level using the syntax: {Public | Private | Dim} <name> as Persistent <type> Using the keyword Dim has the same effect as using Private. Within a subroutine or function, a persistent variable is defined using the syntax. Dim <name> as Persistent <type> In both cases, the <type> element may be any numeric type (e.g. Byte, Integral, Single, etc.), Boolean or a user-defined type (structure or enumeration). A persistent string must be defined using the bounded string syntax (Section 2.11.1), i.e. Dim <name> as Persistent BoundedString(<size-expr>) The <size-expr> element must be a constant integral expression that specifies the number of bytes to reserve for the persistent string’s characters. Examples Dim kbdAttached as Persistent Boolean Private signOnMsg as BoundedString(25) It is important to note that the implementation of the PersistentString type is identical to that of the BoundedString type and is therefore not protected from overwriting the boundaries of the data item. To protect against overwriting, it is advisable to explicitly limit the size of the string to be written. Arrays of persistent variables may be defined as well. To do so, simply add the array dimension list to the variable name in the same manner as for regular variables. If no lower bound is specified, the default array base applies.