Seeting array variables in For-Next loop


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2003
    Location
    Sydney, Australia
    Posts
    126

    Default Seeting array variables in For-Next loop

    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.

  2. #2
    sinoteq's Avatar
    sinoteq Guest


    Did you find this post helpful? Yes | No

    Default Take a look at...

    http://www.picbasic.co.uk/forum/show...ighlight=array

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

  3. #3
    Join Date
    Feb 2003
    Location
    Sydney, Australia
    Posts
    126


    Did you find this post helpful? Yes | No

    Default

    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.

  4. #4
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Default

    No: ch[64] var byte
    Yes: ch var byte[64]
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  5. #5
    Join Date
    Feb 2003
    Location
    Sydney, Australia
    Posts
    126


    Did you find this post helpful? Yes | No

    Default

    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.

  6. #6
    Join Date
    Feb 2003
    Location
    Sydney, Australia
    Posts
    126


    Did you find this post helpful? Yes | No

    Default

    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.

Similar Threads

  1. Simple Array Demo
    By Archangel in forum Code Examples
    Replies: 5
    Last Post: - 15th February 2010, 05:46
  2. Controlsystem for compact sporting (clay shooting)
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 30th July 2009, 17:48
  3. Using input from Switch to control a loop
    By MrRoboto in forum mel PIC BASIC
    Replies: 9
    Last Post: - 2nd February 2009, 06:02
  4. Serial Relays
    By tazntex in forum General
    Replies: 3
    Last Post: - 17th May 2007, 18:42
  5. Reading Array values into variables
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 21st March 2005, 11:30

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts