News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Is it possible to have a Constant array

Started by JohnB, Apr 05, 2023, 04:52 PM

Previous topic - Next topic

JohnB

I know you can do something like this with CData but is it possible to have a constant array. elements of which I can extract by Index.  I was looking for a neat way of converting a number into a string. e.g. 0 represents "Off", 1,represent "On", 2 represents "Auto"
JohnB

top204

An actual array of constants is not possible in the compilers John, but the Dim As Flashx statements and the CReadx functions operate in a similar manner.

For example, to create an array of constants use something like:

Dim MyConstArray8 As Flash8 = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13

Then to read from the table, use:

MyByte = Cread8 MyConstArray8[bIndex]

As can be seen, it operates the same way, with a name of the table (constant array)  and an index to its elements, and a size of the values in the table to read.