Using PEEK command to read data from Array

Started by bvdb, May 16, 2020, 06:57:45 am

Previous topic - Next topic


I have tried the following without success

Dim CalDat(50)

POKE VAR CAlDat(1),1,3 works

H=PEEK VAR CalDat(0)   gives an error
H=PEEK VAR CalDat(1)   gives an error
H=PEEK VAR CalDat(0),1 gives an error

Apparently all numbers are stored as 4 bytes.

Can anyone tell me how to use the PEEK command to read the byte values from an Array?


Just wondering but why do you want to do something so awkward and rare?



Hi John,

The array CalDat() contains calibration information for an instrument we communicate with for testing. Instead of storing the calibration information into a file I would like to store it into a flash memory in the instrument.  That way the calibration data is local to each of the instruments we communicate with.  The flash memory requires bytes to be stored one by one.  I need to be able to read the four bytes that constitutes a floating point number from the CalDat() array one by one and save them into the flash memory.




Hi Bert,

Forget the POKE. This will not store the 4 byte REAL, but only one byte. I suggest the following:
DIM CalDat(50)
Store the calibration data in the array.
Now type MEMORY and Basic will give you the addresses of PROGRAM, simple variables and arrays/strings. The last catagory is of interest. With PEEK you can read the values starting at the address given by MEMORY. As far as I remember the first 8 bytes are used by the system. This would mean bytes 9, 10, 11 and 12 contain the REAL value of CalDat(0), 13,14,15 and 16 CalDat(1), etc. But you have to check this. This worked at least for me in DMBasic 2.7, which I still use.


BTW I calculated your age from the last message and I'm only 3 years younger. Seems that only grey haired (or bold) people are working with this kind of hardware and software.


If you can PEEK from a variable, just assign the value of each array element to it one by one.



It is all about the way, the data is presented. The Basic array is filled with floating point values. 4 bytes floating point values is the only var for Basic. As I understood from the message of Bert, is that he is looking to get this FP value byte by byte. That is why I suggested to look for the position of the array and get the 4 byte values by PEEK.