Shop OBEX P1 Docs P2 Docs Learn Events
Byte(2) variable and UNKNOWN COMMAND: LET — Parallax Forums

Byte(2) variable and UNKNOWN COMMAND: LET

Joe GrandJoe Grand Posts: 70
edited 2006-02-09 01:56 in General Discussion
Hi everyone-

I'm working on some parsing routines in SX/B and have run into a problem that I've been pulling my hair out for most of the day. This is my first experience programming with SX/B and I've been making some pretty good progress until this issue. I'm using SX-Key v3.10 and SXB 1.42.01.

Here is the relevant, problematic code:
rcvBuf        VAR    Byte(8)
tmpWord        VAR    Byte(2)

tmpWord = 0

FOR idx1 = 0 TO 6
  IF rcvBuf(idx1) <> "." THEN
    rcvBuf(idx1) = rcvBuf(idx1) - "0"
    tmpWord = tmpWord * 10
    tmpWord = tmpWord + rcvBuf(idx1)
  ENDIF
NEXT




The code should take a string like "00033.4" and convert it to two bytes: $014E (which is 334 in decimal). I'm getting the following error:

Error 16, Pass 1, UNKNOWN COMMAND: "LET"

If I change tmpWord to a single Byte, the program will compile fine, but will overflow the variable for any string longer than "00025.5". Is SXB not designed to handle words (16-bit) variables or am I just doing something else wrong? Actually, the program SHOULD be using three bytes to handle any string up to "99999.9", but I'm having enough trouble with 2 bytes at the moment.

Any help would be appreciated! [noparse]:)[/noparse]

Joe

Comments

  • BeanBean Posts: 8,129
    edited 2006-02-09 01:13
    Joe,
    You are correct. Currently SX/B only works with byte variables. I have written some routines to do WORD math. I'll see if I can dig them up and I'll post their location for you.
    [noparse][[/noparse]edit]
    Okay found it. It's at this post, go about 3/4 of the way down and you'll see MATH16.SXB download that.
    Feel free to just cut-n-paste the WORD_MULT_BYTE and the WORD_ADD_BYTE routines.

    http://forums.parallax.com/showthread.php?p=559038


    [noparse][[/noparse]EDIT AGAIN]
    Oops, found a bug in the WORD_MULT_BYTE routine. Joe if you already downloaded it, please get it again. I fixed it and reposted it.

    Joe here is the code I used to test it...

    Start:
      PUT rcvBuf, "00012345" ' FOR TESTING ONLY
      tmpWord = 0
      FOR idx1 = 0 TO 6
        IF rcvBuf(idx1) <> "." THEN
          rcvBuf(idx1) = rcvBuf(idx1) - "0"
          WORD_MULT_BYTE tmpWord, 10 ' tmpWord = tmpWord * 10
          WORD_ADD_BYTE tmpWord, rcvBuf(idx1) ' tmpWord = tmpWord + rcvBuf(idx1)
        ENDIF
      NEXT
    
    


    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    "Ability may get you to the top, but it takes character to keep you there."


    Post Edited (Bean (Hitt Consulting)) : 2/9/2006 1:35:08 AM GMT
  • Joe GrandJoe Grand Posts: 70
    edited 2006-02-09 01:56
    Thanks Bean! Those routines are perfect and will come in handy for some other functions, as well. [noparse]:)[/noparse]

    The function you posted should work well with a string up to "6553.5", which would give us $FFFF. Now, this may be too much to ask (as you've already solved my initial problem), but if I had the string "99999.9", the maximum possible in the field I'm receiving, that would require a three-byte value: $F423F (well, $0F423F). I suppose I'd need to put together routines that work with LONG variables (32-bit) now instead of WORD. Could I somehow make use of your 16-bit functions?

    Joe
Sign In or Register to comment.