PDA

View Full Version : Seeting array variables in For-Next loop



bcd
- 28th October 2007, 01:51
Hi Guys,

I have a problem with is probably Sunday morning foggy head, but I cannot remember for the life of me how to assign values to an array. What I want to do is load up a 65 byte array with 0s that will then be changes based on a RS232 command that comes in.

The issues I have is with trying to assign values as part of a for-next loop:

<code>
ch[64] var byte

for x = 0 to 63
ch[x] = 0
next
</code>

This gives me a compile error, as does ch(x) = 0.
I have checked the manual and tried searching the forums, but can find nothing useful.

Help !!

bill.

sinoteq
- 28th October 2007, 03:18
http://www.picbasic.co.uk/forum/showthread.php?t=544&highlight=array

There are lots of tips and tricks there. It's under the FAQ section.

bcd
- 28th October 2007, 04:03
I saw that, but it is only seems relevant if you want to pull a bit out of a byte array.

What I want to do is pull a byte out of a byte array, but I cannot find the syntax to say 'assign this value to value X of the array'

Or am I looking straight at the solution without seeing it??

bill.

paul borgmeier
- 28th October 2007, 06:41
No: ch[64] var byte
Yes: ch var byte[64]

bcd
- 28th October 2007, 06:58
Update :
This seems to let me define the blank array, although due to other issues I cannot compile it and test it. I am assuming that the fact I no longer get an error on that line means it will work.

<code>
for x = 1 to 64
<tab>ch0[x] = 0
next
</code>

I am now having issues getting single values into or out of the array. AM I DOING SOMETHING STUPID????

ch[1] = 255
will compile with a message 'ERROR: Redefinition of LABEL ch'

I am also trying to send a byte from the array out the HSEROUT command. I have tried :
HSEROUT[ch[2]]
but get a message about it being a Bad Expression.

Please help !!

bill.

bcd
- 28th October 2007, 07:01
Paul,

I just saw your post after I hit submit on the post I just completed.

Thank you for that. I can stop pulling out the hair I have left.
I knew I must have been doing something really stupid!!

Thanks again,

bill.