Shop OBEX P1 Docs P2 Docs Learn Events
adding 2 word variables together problem — Parallax Forums

adding 2 word variables together problem

rtumattrtumatt Posts: 8
edited 2012-05-07 11:43 in BASIC Stamp
Hi All,

I have 1 random generated var declared as word as shown below:

random1 = A
key = random1

key = A

when i assign key to the value random1 all is as expected but if i did:

key = key + random1

I would expect:

key = AB (assuming random1 has ran twice)

however what i get is still only 1 character which might be something like

key = %

I cant quite explain this, what im wanting is to generate random word variable 10 times and end up with something like

key = &^43tTr4££

Any help greatly appreciated.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-05-05 06:48
    You're trying to do a string catenate operation where you do "X" + "Y" and get "XY". It doesn't work that way. There are no string variables and no string operations (like "+") in Stamp Basic other than some special cases in some I/O statements. You can define an array of bytes and build up your password one character at a time, put a zero byte at the end and use the STR operator in a SEROUT statement to output the whole thing in one operation, but you have to do string manipulation a byte at a time using non-string operations and byte arrays.

    You could do:
    i var nib
    random1 var byte
    key var byte(11)
    for i = 0 to 9
       ' calculate random1
       key(i) = random1
    next
    key(10) = 0
    serout pin, baud, [str key]
    
  • rtumattrtumatt Posts: 8
    edited 2012-05-07 11:43
    Thats great thankyou, still getting used to this syntax.
Sign In or Register to comment.