Disable keys in program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • muddasirmunir
    Contributor
    • Jan 2007
    • 284

    Disable keys in program

    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:

    [CODE=vb]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[/CODE]

    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?
    Last edited by Killer42; Dec 20 '07, 11:42 PM.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    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.

    Comment

    • QVeen72
      Recognized Expert Top Contributor
      • Oct 2006
      • 1445

      #3
      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
      Last edited by Killer42; Dec 20 '07, 11:46 PM.

      Comment

      • muddasirmunir
        Contributor
        • Jan 2007
        • 284

        #4
        Thanks for nice suggestion


        Originally posted by QVeen72
        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

        Comment

        • Ali Rizwan
          Banned
          Contributor
          • Aug 2007
          • 931

          #5
          Use modules for writing the code single time for entire project.

          Regards

          >> ALI <<

          Comment

          Working...