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
|
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 cls 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? |
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
|
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.. |
Author: | Tony [ Mon May 24, 2004 11:29 pm ] |
Post subject: | |
hah, that's alright - we're all(most of us?) here to learn |
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 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. |