Author |
Message |
l0tt0
|
Posted: Thu Oct 23, 2003 4:52 pm Post subject: Get Value Certain Length |
|
|
Is there anyway taht when you use
get variable
that it can only be a certain amount of characters?
Say I have a yes or no question i just want them to enter y or n...
anyone? thanks in advance |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Thu Oct 23, 2003 5:09 pm Post subject: (No subject) |
|
|
code: |
var letter:string(1) %<- note the (1), its important
getch(letter)
put letter
|
getch() reads a single character from input buffer. If you want more then a single letter of input, you would run getch in a forloop. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
PaddyLong
|
Posted: Thu Oct 23, 2003 8:42 pm Post subject: (No subject) |
|
|
a function I just wrote up ... hope it does what you need
it will get characters for the string until enter is pressed or until there are the set number of characters. if you want it to keep going even if they push enter (so it will always get exactly the number of characters you specify) then take out the "ord (ch) = 10 or " in the exit statement
code: |
function getWord (wordLength : int) : string
var word, tempWord : string := ""
var ch : string (1)
loop
getch (ch)
if ord (ch) >= 32 and ord (ch) <= 126 then
put ch ..
word += ch
elsif ord (ch) = 8 and length (word) >= 1 then % if it is backspace
tempWord := word
word := ""
locate (whatrow, whatcol - 1)
put " " ..
locate (whatrow, whatcol - 1)
for q : 1 .. length (tempWord) - 1
word += tempWord (q)
end for
end if
exit when ord (ch) = 10 or length (word) = wordLength
end loop
put ""
result word
end getWord
var someString : string
someString := getWord (5)
put someString
|
|
|
|
|
|
|
hackman
|
Posted: Mon Oct 27, 2003 11:45 am Post subject: (No subject) |
|
|
Not realy relavent but...what dose ch in getch stand for? |
|
|
|
|
|
Tony
|
|
|
|
|
hackman
|
Posted: Tue Oct 28, 2003 11:46 am Post subject: (No subject) |
|
|
i meant in the getch comand, as in
var ans:string (1)
getch (ans) |
|
|
|
|
|
Tony
|
|
|
|
|
hackman
|
Posted: Wed Oct 29, 2003 10:51 am Post subject: (No subject) |
|
|
wohoo my guese was right! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|