PDA

View Full Version : ArrayWrite question



Charles Linquis
- 10th January 2010, 02:52
If I use the command:

ARRAYWRITE TestArray,[SKIP N,$81,$CF,$4D....]

Where N = $A,

Will it start filling TestArray with $81 at location $A, and leave locations 0-9 untouched?

Darrel Taylor
- 10th January 2010, 03:16
ARRAYREAD has a SKIP modifier.
ARRAYWRITE does not.

Maybe you could ...

ARRAYWRITE TestArray,[STR TestArray\N,$81,$CF,$4D...]

Which writes the first N bytes back to themselves.
<br>

Charles Linquis
- 10th January 2010, 17:20
So, in the above example,

ArrayRead [SKIP N,$81,$CF,4D...]

Would give me an array with $81 in location $A, and locations 0-9 untouched?

Darrel Taylor
- 10th January 2010, 21:19
NO, that would give compile errors.
ARRAYREAD gets data from an array. So you can't have constants as parameters.

ARRAYWRITE puts data in an array.

Consider the following program ...
TestArray VAR BYTE[26]
N VAR BYTE
N = 9

ARRAYWRITE TestArray,["ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
HSEROUT ["Before-",STR TestArray\26,13,10]

ARRAYWRITE TestArray,[STR TestArray\N,"12345678"]
HSEROUT ["After -",STR TestArray\26,13,10]
The output would look like this, and the data can be moved by changing the value of N. ...
Before-ABCDEFGHIJKLMNOPQRSTUVWXYZ
After -ABCDEFGHI12345678RSTUVWXYZ


If the data is always going to be placed at the same location, you can do it this way...
TestArray VAR BYTE[26]
StartPos VAR TestArray[9]

ARRAYWRITE TestArray,["ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
HSEROUT ["Before-",STR TestArray\26,13,10]

ARRAYWRITE StartPos,["12345678"]
HSEROUT ["After -",STR TestArray\26,13,10]
Resulting in the same thing ...
Before-ABCDEFGHIJKLMNOPQRSTUVWXYZ
After -ABCDEFGHI12345678RSTUVWXYZ
<hr>ADDED:
You can also do the fixed position data like this ...
TestArray VAR BYTE[26]

ARRAYWRITE TestArray,["ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
HSEROUT ["Before-",STR TestArray\26,13,10]

ARRAYWRITE TestArray(9),["12345678"]
HSEROUT ["After -",STR TestArray\26,13,10]

Unfortunately, you can not do it like this, which would be very handy...
TestArray VAR BYTE[26]
N VAR BYTE
N = 9

ARRAYWRITE TestArray,["ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
HSEROUT ["Before-",STR TestArray\26,13,10]

ARRAYWRITE TestArray(N),["12345678"]
HSEROUT ["After -",STR TestArray\26,13,10]


hth,

phoenix_1
- 10th January 2010, 21:21
As our friend Darrel Taylor write
http://www.picbasic.co.uk/forum/attachment.php?attachmentid=3875&stc=1&d=1263158154
Here is example :
If you have array = "ABCDE"
And you do next :


A var byte[5]
B0 var byte : B0 = 10
ARRAYWRITE A, [DEC B0]

You will have next :
array = "10CDE"
Best regards to all and special to Darrel

Charles Linquis
- 11th January 2010, 00:42
Thanks to both of you!