PDA

View Full Version : loop through input string?



elementis
09-09-2008, 09:15 AM
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?

Unsoundcode
09-09-2008, 09:38 AM
Hi, DEBUGIN can actually place an input string into an array, look at the Special Formatters in the DEBUGIN help file and check out the STR ByteArray \L \E instruction.

Each element of that array can then be addressed via it's index, ByteArray(0),ByteArray(1),ByteArray(2).........etc .

Jeff T.

elementis
09-10-2008, 05:19 AM
Ok I get the concept,
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?

Unsoundcode
09-10-2008, 12:23 PM
Hi,

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.

elementis
09-11-2008, 06:01 AM
EDIT: disreguard that question, I figured it out myself



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?

Dave-W
09-11-2008, 06:45 AM
Elementis,

Now you can connect a small speaker and here the morse code also! Sounds like fun.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave W.