ndudman wrote:I guess didnt understand if I initilized with =((A,B,C))it then it would be created in program memory and thus read-only...
You may be confusing two different (but somewhat related) things. RAM-based variables can optionally have an initializer but only if they are scalar (i.e. not an array). Example:
This is equivalent to:
This is a typing shortcut only, the generated code is (nearly) identical.
In contrast, ZBasic does support initialized arrays of data in Program Memory. The original syntax for specifying the initialization data (invented by NetMedia for the BasicX devices) requires the name of a separate file to be specified, which file contains the data values. ZBasic supports this but it also supports specifying the data inline, e.g.
Code: Select all
Dim pmData as ByteVectorData ({ &H21, &H35, &Hff })
This is more convenient for most applications because it keeps the data together with the code that uses it. The form shown above is considered read-only because the compiler won't allow you to assign values to the array. A different keyword
ByteVectorDataRW can be used to allow the array to be read-write. This, too, is a carryover from BasicX.
ndudman wrote:So I have to set each element individually or have the READ_ONLY version of the array to reset my working r/w copy of byte array.
Yes, those are the choices. If you have more than just a few elements in the RAM array, it will be more efficient (time and code space) to define the Program Memory data array and copy it over the RAM-based array to initialize it.
Code: Select all
Dim pmData as ByteVectorData ({ 1, 2, 3})
Dim myData(1 to 3) as Byte
Call GetProgMem(pmData.DataAddress, myData, SizeOf(myData))
The code above will copy more data than it should if the Program Memory data item has fewer elements than the RAM array. This can be remedied thusly:
Code: Select all
Call GetProgMem(pmData.DataAddress, myData, Min(Sizeof(pmData), SizeOf(myData)))