Computer Science Canada

Disabling some keys on keyboard

Author:  Mewbro [ Sun May 23, 2004 3:25 pm ]
Post subject:  Disabling some keys on keyboard

How would i go about disabling all the keys except 0-9..
I'm making a program that makes you input 12 numbers and it does some stuff.. since 12 digit intergers are too big.. i made it into string.. but i wanna disable all the letters..

Well, i haf a long way that requires 12 getch keys.. and then uses catenation to add up all 12 and put it into a variable.. it's long and messy.. i just wanna know if there's a way of shortening it.. thnx

Author:  Tony [ Sun May 23, 2004 3:56 pm ]
Post subject: 

you could check each character inside a forloop using index function

var valid : boolean := true
var text : string := "123456789012"

for i : 1 .. length (text)
    if index ("1234567890", text (i)) > 0 then
        valid := false
    end if
end for

if valid then
    put "valid input"
    put "invalid input"
end if

Author:  Delos [ Sun May 23, 2004 3:57 pm ]
Post subject: 

'getch' sounds good.

Loops sound just as good.

Some place to keep track of how many characters entered would be a good idea.

chr() and ord() are even more useful, I'd say.

If you still can't get it, repost.

Author:  Mewbro [ Mon May 24, 2004 11:26 am ]
Post subject: 

I see wat you're doing tony, but i wanna stop them from typing letters completely...

i have something like:

getch (ch)
if ch <"0" and ch>"9" then
end if

but that takes too long if i have a 12 digit string..

Author:  Tony [ Mon May 24, 2004 2:37 pm ]
Post subject: 

have you thought of putting that in a loop? Laughing

Author:  junkpro11 [ Mon May 24, 2004 10:02 pm ]
Post subject: 

maybe use strint, loop, and if statements

get the input as a string, then see if u can convert it to int

if it works then proceed with the loop or watever in the loop, if not the put error or watever u want


var snum:string
var icount:int
get snum
if strintok (snum)=true then
watever u do with num
put "error....blah blah"
end if
exit when icount:=12
end loop

Author:  Tony [ Mon May 24, 2004 10:16 pm ]
Post subject: 

junkpro11 : that's not going to work, as a 12 digit number overflows an integer

Author:  junkpro11 [ Mon May 24, 2004 10:22 pm ]
Post subject: 

oh....12 digit

sorri...didnt realli read the problem, sorta skim thru it, i thought it was 12 numbers and not 12 digit.....

sorri!! just seeing if i can help...but then again i need help myself.. Embarassed

Author:  Tony [ Mon May 24, 2004 11:29 pm ]
Post subject: 

hah, that's alright - we're all(most of us?) here to learn Laughing

Author:  Frank [ Thu May 27, 2004 5:54 pm ]
Post subject:  You can try this:

I call this fool proofing, you can call it what ever you want. If your teacher doesn't restrict you than use the "strintok" function (because they want to give you a challange) than this is perfect.

It looks like this:


var input : string

put "Please enter a integer number."
get input
exit when strintok (input)
end loop


The program will ask the user for an input like shown above, and the "strintok" will check is the input can be converted to a integer. If the input ONLY contains integers the loop will exit, allowing you to continue on with your program. If the input can not be converted can NOT be converted to an integer than it will clear screen and loop again as if nothing happened untill the users enters an integer.

If you want them to enter 12 numbers then just use a "for loop" to loop 12 times surrounding your previous loop and store the added value of the 12 inputs in another variable which will be the sum.

If your comfortable using "ord" than you might want to use that. It's longer, more difficult (not that much), and you'll have to create your own function, but if this is for a class, it may get you more marks(depending on the teacher and ciriculum).

I think that's all. Send a message back telling me if this solved your problem. If you need extra help on this, or your teacher does restrict you from using "strintok" then post another message and I'll be glad to help you out.