Welcome to Dream.In.Code
Become a VB Expert!

Join 149,952 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,334 people online right now. Registration is fast and FREE... Join Now!




How to disable the keys

 
Reply to this topicStart new topic

How to disable the keys

muddasir
20 Dec, 2007 - 03:20 AM
Post #1

D.I.C Head
Group Icon

Joined: 14 Jan, 2007
Posts: 106



Thanked: 4 times
Dream Kudos: 200
My Contributions
i am using vb6
i want that in my whole programe user can
only put data in numbers(0-9) alphabetes(a*-z)
and .(dot/point) only.
now how can i disable all the other keys

i know the code how to permit the keys in
the key press evet of any textbox
whic i uses this code

QUOTE
Dim comp As Boolean
comp = Chr(KeyAscii) Like "[1-9.0]"
If Chr(KeyAscii) = vbBack Then Exit Sub
If comp = False Then
KeyAscii = 0
End If


now insted of writing it to all the text boxes
(which are huge in no) i want to disable the
other keys in start module
how to do this

User is offlineProfile CardPM
+Quote Post

Martyr2
RE: How To Disable The Keys
20 Dec, 2007 - 09:41 AM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
All you need to do is create a function that takes in an integer and returns a boolean. The integer passed to the function will be the keyascii which you will validate and return true or false on whether or not to discard it. Then in each textbox event all you need to do is pass the keyascii parameter to the function and throw it in an if statement on whether not to allow it through.

CODE

Private Sub txtBox1_KeyPress(ByVal KeyAscii As Integer)
    ' Call our event and use its boolean return value to determine if we should exit the keypress or let it through
    if not myfunction(KeyAscii) then
        KeyAscii = 0
        Exit sub
    End if
End Sub


The above example will call our function (in our case I called it "myfunction") and its return value will tell our event whether or not to let it through. You can put similar code into the keypress event of all your textboxes and they can all use the same function forcing validation on them.

Hope that helps!

"At DIC we be keypressing, ascii key evaluating code ninjas!" decap.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 05:49PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month