By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,593 Members | 2,006 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,593 IT Pros & Developers. It's quick & easy.

Disable keys in program

100+
P: 284
I am using VB6.
I want that in my whole program the user can only enter data as numbers (0-9), alphabetical (a-z) and . (dot/point).
How can I disable all the other keys?

I know the code how to permit the keys in the keypress event of any textbox
by using this code:

Expand|Select|Wrap|Line Numbers
  1. Dim comp As Boolean
  2. comp = Chr(KeyAscii) Like "[1-9.0]"
  3. If Chr(KeyAscii) = vbBack Then Exit Sub
  4. If comp = False Then
  5.   KeyAscii = 0
  6. End If
Now instead of writing it to all the text boxes (which are huge in number) I want to disable the other keys in start module.
How to do this?
Dec 20 '07 #1
Share this Question
Share on Google+
4 Replies


debasisdas
Expert 5K+
P: 8,127
Instead of writing all that to the keypress event of all the individual textboxes ,write that in the keypress event of the form and make the KeyPreview property of the form to true.
Dec 20 '07 #2

QVeen72
Expert 100+
P: 1,445
Hi,

You cannot write for the whole project. Instead you can write for each form.
Create it as a general procedure in a .bas module.
Make Form's property : KeyPreview =True
and in Form's KeyPress Event, call that procedure by passing KeyAscii.

Regards
Veena
Dec 20 '07 #3

100+
P: 284
Thanks for nice suggestion


Hi,

you cannot write for the whole project. Instead you can write for each form.
Create it as a General Procedure in .bas module..
Make Form's property : KeyPreview =True
and in Form's KeyPress Event, call that procedure by passing KeyAscii

REgards
Veena
Dec 20 '07 #4

Ali Rizwan
100+
P: 927
Use modules for writing the code single time for entire project.

Regards

>> ALI <<
Dec 21 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.