loop through input string?
elementis
Posts: 3
Ok well I am going to have to admit Im a complete novice at PBASIC, though am not a novice to programming in general.
I just started messing with this language yesterday and am stuck with one thing.
I want to use the DEBUGIN command to get a random string inputted by the user.
Once the input is gotten I want this program to be able to loop through every character in the string, and then to perform the appropriate subroutine depending on the each letter iteration that is passed through the loop.
From my understanding the PBASIC language does not have any built in string handling functions, so that is why im stuck.
How can I get the PBASIC language to take a inputted string and break it down into an array of characters that I can loop through? and how exactly would I loop through each character of that given string?
I just started messing with this language yesterday and am stuck with one thing.
I want to use the DEBUGIN command to get a random string inputted by the user.
Once the input is gotten I want this program to be able to loop through every character in the string, and then to perform the appropriate subroutine depending on the each letter iteration that is passed through the loop.
From my understanding the PBASIC language does not have any built in string handling functions, so that is why im stuck.
How can I get the PBASIC language to take a inputted string and break it down into an array of characters that I can loop through? and how exactly would I loop through each character of that given string?
Comments
Each element of that array can then be addressed via it's index, ByteArray(0),ByteArray(1),ByteArray(2).........etc.
Jeff T.
but if it wouldn't be too much trouble can somebody show me a coded example of using the debugin command to take a variable string, and then maybe debug each character individually from a loop?
ByteArray VAR Byte(6)·········· 'declare 6 byte array
idx VAR Nib
main:
FOR idx=0 TO 5
ByteArray(idx)=0··············· 'fill array with zeros to denote end of string
NEXT
DEBUGIN STR ByteArray\6\CR····· 'input upto a 6 character string
FOR idx=0 TO 5
IF ByteArray(idx)=0 THEN EXIT·· 'check for end of string
DEBUG ByteArray(idx)··········· 'debug 1 character at a time
NEXT
DEBUG CR, STR ByteArray,CR····· 'debug the whole string at once
GOTO main
hope this helps
Jeff T.
Thanks you thats exactly what i needed!
Im pretty much making my first ever program with PBASIC for my electronics class and i decided to go above and beyond my class since i have previous programming knowledge to make a light diode emit a morse code S.O.S based on the users inputted string.
Now that I know how to loop through each character i can finally now easily do the rest!!
thank you very much.
but is it possible to do a string with that example to be able to have up to infinity characters? or even just have a really large number of characters?
Now you can connect a small speaker and here the morse code also! Sounds like fun.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave W.