Getch help
Author |
Message |
TokenHerbz
|
Posted: Tue Sep 06, 2005 6:34 pm Post subject: Getch help |
|
|
I cant find a good tutorial of getch...
Anyways, i think rather then useing get ans (which will want a number) getch is to take in ANY character correct?
Anyways, if im wrong correct me, otherwise help my understand this...
code: |
var answer: int:= 0
proc ans
getch(answer)
if answer = 1 then
exit
end if
end ans
loop
put "Press 1"
ans
end loop
put "You did it, thanks"
|
Yeah i get errors...
Dont laught.. Im horrible at this, meanwhile explaine getchar, and hetch, (or the ones kinda like that)
Please explain there use's, and give me a simple example...
Thank you, and like i said, theres no tut which helped me. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TokenHerbz
|
Posted: Tue Sep 06, 2005 6:38 pm Post subject: (No subject) |
|
|
i got it working with letters, but i cant get it to work with numbers...
code: |
var leave: boolean := false
proc ans
var ch : string (1)
getch (ch)
if ch = 'a' then
leave := true
end if
end ans
loop
put "Press a"
ans
if leave = true then
exit
end if
cls
end loop
put "You did it, thanks"
|
|
|
|
|
|
|
jamonathin
|
Posted: Tue Sep 06, 2005 6:45 pm Post subject: (No subject) |
|
|
First of all, 'getch' only takes ': string (1)' variables (it's probabily in the F10 area). And so what happens is it "getch's" whatever is pressed, without displaying it.
Here is what you needed your program to do. If you take out the comment, theres no more blinking light (cursor).
Turing: | var answer : string (1)
%setscreen ("nocursor")
loop
put "Press 1"
getch (answer )
if answer = "1" then
exit
end if
end loop
put "You did it, thanks" |
Now after you figure that out, you can play with it, and make password things, here's an example thatrelates to that last program.
Turing: |
var answer : string (1)
var total : string := ""
setscreen ("nocursor")
loop
locate (1, 1)
put "Enter your password"
getch (answer )
if answer = (KEY_ENTER ) then
exit
else
total + = answer
locate (2, length (total ))
put "*"
end if
end loop
locate (3, 1)
put "Password = ", total
|
|
|
|
|
|
|
TokenHerbz
|
Posted: Tue Sep 06, 2005 7:21 pm Post subject: (No subject) |
|
|
ok, but i want to getch numbers...
How can u get a number like getch? so that if i press say A, and it was a proc, i can call it...
or if i press 1, then ill do what ever..., like i sayd, i want to use numbers |
|
|
|
|
|
jamonathin
|
Posted: Tue Sep 06, 2005 8:28 pm Post subject: (No subject) |
|
|
Read through what I wrote. Getch can ONLY use : string (1), not any integer value. We can play around with our inputed variabled, and change it into an integer, but we cannot GETCH ( var :int ).
If you are "getching" for a number, use quotes around it in you if statement. Just like I did in that previous post.
Here is another sample program. . .
Turing: |
var input : string (1)
var numb : int
loop
cls
put "Enter a Whole Number."
getch (input )
if strintok (input ) then
numb := strint (input )
exit
else
put "'", input, "' is CLEARLY not a whole number."
delay (1250)
end if
% Or
%exit when strintok (input)
end loop
%numb := strint(input)
put "Thank You. Your number is ", numb, "."
|
|
|
|
|
|
|
Cervantes
|
Posted: Tue Sep 06, 2005 8:37 pm Post subject: (No subject) |
|
|
I wouldn't expect you to understand the code that Jamonathin just posted (the type conversion parts) so, if you wish, you may learn about them in the String Manipulation Tutorial. (It's the second section.) |
|
|
|
|
|
TokenHerbz
|
Posted: Wed Sep 07, 2005 1:06 am Post subject: (No subject) |
|
|
Thank you. |
|
|
|
|
|
|
|