1.11M Members

How to disable letters?

 
0
 

im creating a simple calculator and i dont know how to disable letter in the textbox.. can someone help me please...newbie here....BTW im using VB6...

 
0
 

if the inputted character is letter then
use the statement

KeyAscii=0

you have to write that code on the key press event of the text box

now i hope that you can handle the issue with ASCII VALUES of letters

if you think letters as alphabets then ascii value range is 65 to 90 and 97 to 122

 
0
 
If (KeyAscii <= vbKey9 And KeyAscii >= vbKey0 Or KeyAscii = vbBack) Then
Else
KeyAscii = 0
End If

found this code on youtube but it doesnt on me i got a debug...
can you tell me whats wrong with that code...i put it in the keypress on the textbox...

 
0
 

vbBack is string value

try Asc(vbBack)

 
0
 

try this

If Not (KeyAscii <= vbKey9 And KeyAscii >= vbKey0 Or KeyAscii = vbKeyBack) Then
KeyAscii = 0
End If

hope this helps you to solve the issue

 
0
 

There are 2 ways to do this -

  1. When your textbox looses focus, trap the error...

    If Not IsNumeric(Text1.Text) Then

    MsgBox "Numeric input only!", vbCritical, "Invalid Input"

    Text1.Text = ""

    End If

OR, you can just delete the letter that was typed so it only accepts numbers...

Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Text1.Text) Then 
SendKeys {Backspace}
End If
End Sub

''Note, you HAVE to reference Microsoft Scripting Library in your project...
''This will delete any letters or symbols except for numeric values. The ".," is allowed...
 
0
 

Wow thanks for the help everyone i really learned a lot..
i tried all your answer and it really works... thanks again everyone!!!

Question Answered as of 1 Year Ago by rishif2, AndreRet and TnTinMN
 
0
 

Only a pleasure. Happy coding...

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: