Shop OBEX P1 Docs P2 Docs Learn Events
Can a Method Parameter Call a Data Table Value? — Parallax Forums

Can a Method Parameter Call a Data Table Value?

coryco2coryco2 Posts: 107
edited 2013-07-09 14:36 in Propeller 1
I would like to have a method call a series of values from a data table via a passed parameter, like this:
PUB  MyMethod

    txData(Data1)


PUB txData(dataname) | idx, char

    idx~
    char~
    repeat
      char:= dataname[idx]
      serial.tx(char)
      idx++  
    until char==255
  
DAT

  Data1  BYTE  45, 0, 12, 230, 255

The txData method works if I use char:=Data1[idx] in the repeat loop, but not if I try to pass the dataname as a parameter from myMethod. Why is this please? Is there some syntax I could use to get this to work? Thanks!

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-07-09 14:17
    Try:
    char:= byte[dataname][idx]
    

    I think "dataAddress" would be a better variable name than "dataname".
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-07-09 14:28
    In MyMethod us txData(@Data1) to pass the address of the Data1. In txData you can use Duane's suggestion of byte[dataname][idx] or you could use byte[dataname++]. Also, as Duane suggested you might want to call the parameter dataAddress, since the value that you're passing is really an address and not a name.
  • coryco2coryco2 Posts: 107
    edited 2013-07-09 14:29
    Nope, I already tried that. No go. I thought perhaps it had something to do with passed parameters being longs and the data table being bytes, but it doesn't work if I format the data table as longs either...
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-07-09 14:30
    Dave Hein wrote: »
    txData(@Data1)

    Thanks Dave. I missed the lack of an address symbol.
  • coryco2coryco2 Posts: 107
    edited 2013-07-09 14:36
    As did I. :lol:
    Thanks to you both!
Sign In or Register to comment.