Shop OBEX P1 Docs P2 Docs Learn Events
Help needed with string array — Parallax Forums

Help needed with string array

HIBITDACHIBITDAC Posts: 40
edited 2007-08-04 19:55 in BASIC Stamp
How to I split up a string array,

x var byte(9)

serin 15,84,[noparse][[/noparse]str x\9]

when·I debug it I get 072,33

How do I get the 2 numbers in 2 different variables?

Any help is appreciated.

Sam

Post Edited (HIBITDAC) : 8/4/2007 6:56:46 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-04 19:00
    First thing I wonder is: Why are you using STR? What is the format of the information you're receiving? If it's always in the form of two decimal numbers with a comma or other separator, why not use the DEC formatter? It's much easier than trying to do the conversion by yourself in Stamp Basic. For example:
    x var byte
    y var byte
    
    serin 15,84,[noparse][[/noparse]dec x, dec y]
    
    


    Have a look at the section of the Stamp Basic manual on SERIN and at the appendix on the formatters.
  • HIBITDACHIBITDAC Posts: 40
    edited 2007-08-04 19:15
    I am using a Simmetry CS-2B. The data coming in is the x and y cordinates for my touch screen position that has been touched. I tried the example that you gave and it didnt work, Ive tried:

    x var byte(3)
    y var byte(3)

    serin 15,84,[noparse][[/noparse]str x\3]
    serin 15,84,[noparse][[/noparse]str y\3]

    and that didnt work as well.

    It is always 3 digits seperated by a "," then the last 3 digits.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-04 19:45
    It may be that the Baud is too high for the formatters to work. They're kind of marginal at 9600 Baud on a BS2 and drop characters. If you can change the Baud on the display to 2400 or switch to a faster Stamp, things will work better. I did notice that you didn't have a string terminator character, so I've added one here (a return - 13).

    You can convert to decimal as follows:
    x  var  word
    y  var  word
    i   var  byte
    s  var  byte(9)
    '...
    serin 15,84,[noparse][[/noparse]str s\9\13]
    x = 0
    for i = 0 to 2
    x = x * 10 + (s(i) - "0")
    next
    y = 0
    for i = 4 to 6
    y = y * 10 + (s(i) - "0")
    next i
    
    
  • HIBITDACHIBITDAC Posts: 40
    edited 2007-08-04 19:55
    THANK YOU! You have solved my problem works perfectly!
Sign In or Register to comment.