48 of 158
42 The values specified in an in-line initializer may be literal constants as shown above or they may be named constants that are visible within the module. For example, Const cval as Byte = &H20 Dim d1 as ByteVectorData({ 20, &Hff, cval, "row" }) Program Memory data items have an associated property named DataAddress. The value of this property is the address of the data item in Program Memory. The type of the property is Long for compatibility with BasicX and the GetProgMem() subroutine. Example Dim addr as Long addr = tbl.DataAddress It is possible, also, to use the DataAddress property to get the address of a particular Program Memory data item. To accomplish this, simply add parentheses following the property name and specify the index or indices of the item of interest. The example below will result in addr having the Program Memory address of the second data value of the first row of the table. addr = tbl.DataAddress(2, 1) Caution: Program Memory data tables are arranged in memory in row-major order, i.e. the column values for the first row, followed by the column values of the second row, etc. This is a direct result of scanning the initialization data row by row. When you index a data table, you must specify the column index first and the row index second. This is backward with the respect to the way matrices are often visualized, i.e. (row, column). This strategy was adopted to maintain compatibility with BasicX. See Section 3.18 for more information on array data order. Note that the UBound() function is useful with Program Memory data items to determine the dimensions of the vectors and tables. LBound() will always return 1 since initialized Program Memory data items are always 1-based. For special situations, the data initialization file may be supplied in “raw” form. This means that the initialization file contains actual binary data as opposed to containing formatted data items. You instruct the compiler to interpret the initialization file in raw mode by appending Attribute(raw) to the end of the definition as in the example below. Note, particularly, that raw mode can only be used for numeric types (i.e. not String types) and can only be used for vector types (i.e. not table types). Also, the data file must contain an integral number of data elements. For example, for IntegerVectorData the data file must contain an even number of bytes. Dim d1 as ByteVectorData("mydata.dat") Attribute(raw) Program Memory variables may also be defined using a syntax similar to that used for defining RAM- based variables, using the keyword attribute ProgMem preceding the type name. For example, Dim d1(1 to 20) as ProgMem Byte This defines and reserves space for an array of bytes in Program Memory. Variables defined in this way will be zero-filled. Strings in Program Memory may be defined as well using the bounded string syntax. In this case, the string will have an initial value representing an empty (zero length) string. Dim ps as ProgMem BoundedString(15) Program memory structures may also be defined, see Section 3.25 for more details. A Program Memory variable may also be defined using Based keyword, see Section 3.22 for more details.