Shop OBEX P1 Docs P2 Docs Learn Events
How to Read and write a two dimensional array in pbasic? — Parallax Forums

How to Read and write a two dimensional array in pbasic?

tripjacktripjack Posts: 13
edited 2006-11-20 23:57 in General Discussion
Hi,

I'm trying to read from a table in pbasic on a BS2sx.

I loaded the following data

r0 DATA "1234", "5678"
r1 DATA "ABCD", "EFGH"

I'm noticing that the READ command only returns bytes.
so the command :

READ r1, strByte
returns 1

Can someone suggest a subroutine in pbasic that I specify the row and column of my data and it returns the whole string?·· eg: r1 c1 returns "EFGH"

Thanks,
David

·

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-11-19 14:22
    A 2-D array: 8 cells; 2 rows, 4 cols; using ADDRs $01 - $08

    r· VAR· Nib
    c· VAR· Nib

    cell = r * c

    READ·cell, contents

    Post Edit -- You could jamb this up with bad values (r, c), but I think you get the idea.

    Post Edited (PJ Allen) : 11/19/2006 2:28:29 PM GMT
  • tripjacktripjack Posts: 13
    edited 2006-11-20 23:57
    THANKS PJ for putting me on the right track

    I used this code and it works great!

    MaxCols CON   8                  ' number of cols in table
    ColB    CON   4                  ' width of each column in bytes
    RowB    CON   ColB * MaxCols     ' width of each row in bytes
    
    

    ·
    addrW   VAR  WORD                 'output returned value
    nRow    VAR  BYTE                 'input row number
    nCol    VAR  BYTE                 'input column number
    
    

    ·
    addrW = ((nRow*RowB) +(nCol * ColB))
    

    Thanks,
    David

    ·
Sign In or Register to comment.