Shop OBEX P1 Docs P2 Docs Learn Events
Quick Code Clean-Up Question - ANSWERED! — Parallax Forums

Quick Code Clean-Up Question - ANSWERED!

JomsJoms Posts: 279
edited 2010-01-29 06:53 in Propeller 1
I have my program working, just trying to get my code cleaned up. I thought this is the way I have done this several times before, but running into problems. It works using the part that is commented out, but when I switch the the 'repeat' loop, it will give me errors in the data.

Does anyone see any quick things I am missing here?

Thanks!

PUB SetTD | i,t             'Set Time/Date PUB

  Repeat While i < 11
    tempStr[i] := Serial.GetChar
    i++

{

  tempStr[noparse][[/noparse]0] := Serial.GetChar                  
  tempStr[noparse][[/noparse]1] := Serial.GetChar                      
  tempStr[noparse][[/noparse]2] := Serial.GetChar                      
  tempStr[noparse][[/noparse]3] := Serial.GetChar                  
  tempStr[noparse][[/noparse]4] := Serial.GetChar                      
  tempStr[noparse][[/noparse]5] := Serial.GetChar                      
  tempStr[noparse][[/noparse]6] := Serial.GetChar
  tempStr[noparse][[/noparse]7] := Serial.GetChar 
  tempStr[noparse][[/noparse]8] := Serial.GetChar 
  tempStr[noparse][[/noparse]9] := Serial.GetChar 
  tempStr[noparse][[/noparse]10] := Serial.GetChar 
  tempStr[noparse][[/noparse]11] := Serial.GetChar   

 }
[/i]

Post Edited (Joms) : 1/29/2010 3:32:48 AM GMT

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2010-01-29 03:21
    IIRC, local variables are uninitialised (except result). So why don't you use repeat i from 0 to 11?
  • JomsJoms Posts: 279
    edited 2010-01-29 03:30
    that makes sense.... I was trying to put i:=0 and thought that would help. I remember using the repeat command like you listed and tried it here, and it works great!

    THANKS FOR THE QUICK HELP!
  • wyzard28wyzard28 Posts: 24
    edited 2010-01-29 06:53
    That probably should be:

    Var
      tempstr[noparse][[/noparse]12]
    
    Obj
      serial  :  "yourserial"
    
    Pub  SetTD | i, t
    
      Repeat i from 0 to 11
    [size=2][code]
         tempStr[i] := Serial.GetChar
    .................| don't forget to index tempStr[noparse][[/noparse]n] above!
    [/i]
    


    [/code][/size]
    Post Edited (wyzard28) : 1/29/2010 6:58:52 AM GMT
Sign In or Register to comment.