Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Disabling some keys on keyboard
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Mewbro




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sun May 23, 2004 3:56 pm   Post subject: (No subject)

you could check each character inside a forloop using index function
code:

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

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

if valid then
    put "valid input"
else
    put "invalid input"
end if
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Delos




PostPosted: Sun May 23, 2004 3:57 pm   Post subject: (No 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.
Mewbro




PostPosted: Mon May 24, 2004 11:26 am   Post subject: (No 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
cls
end if

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




PostPosted: Mon May 24, 2004 2:37 pm   Post subject: (No subject)

have you thought of putting that in a loop? Laughing
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
junkpro11




PostPosted: Mon May 24, 2004 10:02 pm   Post subject: (No 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

code:

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




PostPosted: Mon May 24, 2004 10:16 pm   Post subject: (No subject)

junkpro11 : that's not going to work, as a 12 digit number overflows an integer
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
junkpro11




PostPosted: Mon May 24, 2004 10:22 pm   Post subject: (No 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
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon May 24, 2004 11:29 pm   Post subject: (No subject)

hah, that's alright - we're all(most of us?) here to learn Laughing
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Frank




PostPosted: 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

loop
put "Please enter a integer number."
get input
exit when strintok (input)
cls
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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: