-
How do I check a textbox for characters when it should only accept chars? Also I am having trouble formatting the text.
I would like to take the number entered and convert it to a percentage( 10 should look like this 10%) and one for time(1hr and 15min should look like this 1.15) Please help
-
Sorry if I hav understood this wrong, by "characters" do you mean text & not numbers?
If so you could do something like:
Code:
private sub command1_click()
If isnumeric(text1.text) then
MsgBox"please type letters only!"
End If
With the next part, you could use the format function...
format(text1.text, "##" & "%") or
Format(text1.text, "#.##")
Hope this helps!
Alex Read
-
textbox
Hey Alex
the formatting isn't working, whenever I enter a number i t automatically multiplies it by 100(10 looks like 1000%) also I made a typo I am checking for text that should be numbers
-
Use If Not Isnumeric(text1.text) then...
And also:
Format(text1.text, "##")
text1.text = text1.text & "%"
Hope this helps! :p
-
Or you could capture the keys in the key press event:
To disable numbers any other characters,
Private Sub text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 65 To 90:
Case 97 to 122:
Case 8: 'backspace
Case Else
Beep
KeyAscii = 0
End Select
End Sub
-
Try the following:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Or KeyAscii = 32 Then Exit Sub
If Not Chr(KeyAscii) Like "[A-z]" Then KeyAscii = 0
End Sub