Shop OBEX P1 Docs P2 Docs Learn Events
Lost in arrays... — Parallax Forums

Lost in arrays...

WolfbrotherWolfbrother Posts: 129
edited 2009-06-12 00:39 in BASIC Stamp
Hi all,

I'm still struggling with my datalogger project and trying to get a simple array to fill open spaces, so to speak.

I wrote this code to accept an input up to 20 characters and if one of those characters is a * to fill the rest of the spaces with # signs. In the final version, I will be reading words from a datalogger and looking for a space, when I see the space, I want to fill the rest of the 20 characters with spaces. I am guessing I am doing something so simply wrong that I can't find it. Help?
' {$STAMP BS2}
' {$PBASIC 2.5}
 
index       VAR      Nib
temp        VAR      Byte
ctr         VAR      Byte
ctr2        VAR      Byte
userEntry   VAR      Byte(20)

DEBUG "enter word;"
  FOR ctr=1 TO 20
  DEBUG CR," ctr = ", DEC ctr
    DEBUGIN STR userEntry\(ctr)
      IF userEntry(ctr)<> "*" THEN
      GOTO jumpone
      ELSEIF userEntry (ctr)= "*"  THEN
                          'user entry is a * so fill array with #'s
                          'increment from ctr to 20 to fill.
          FOR ctr2 = ctr TO 20
          userEntry(ctr)="#"         ' filling array with #'s
          DEBUG STR userEntry \(ctr)
          NEXT
          GOTO jumptwo
      ENDIF
jumpone:
DEBUG CR,"jumpone", CR
   NEXT
   END
jumptwo:
DEBUG "jumptwo", CR
  DEBUG STR userEntry \20
  END

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-06-11 22:05
    Hi, what·you could··do is create a subroutine to handle your input. At the beginning of the subroutine fill the array with "#" , now all you have to worry about is the input from the user
    Start of subroutine
    

    For ctr=0 to 19
    userEntry(ctr)="#"
    Next
    

    If userEntry is being filled a byte at a time you need to address each element in turn·and each time check for the "*"

    For ctr=0 to 19
    DEBUGIN temp
    If temp = "*" Then
    Exit
    Else
    userEntry(ctr)=temp
    Endif
    Next
    DEBUG STR userEntry\20
    RETURN
    

    Jeff T.
  • WolfbrotherWolfbrother Posts: 129
    edited 2009-06-12 00:39
    thank you. I knew I was just overlooking something. It works just fine, now I have to add this into the datalogger thing.
Sign In or Register to comment.