|
-
Feb 13th, 2004, 12:14 AM
#1
Thread Starter
Fanatic Member
Prevent User input letters.
i have a text box which is suppose to key in decimal or integer..and not letters or commas etc... how do i prevent that?
-
Feb 13th, 2004, 12:22 AM
#2
Addicted Member
-
Feb 13th, 2004, 12:52 AM
#3
Thread Starter
Fanatic Member
humm..though i dunnno why i cannot open up the exe successfully....Unablr to set the version compatible component...is there other alternatives?
-
Feb 13th, 2004, 01:07 AM
#4
Addicted Member
Ok try this,
VB Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii < 48 Or KeyAscii > 57) And NotDecimal(KeyAscii) And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
Private Function NotDecimal(KeyAscii As Integer) As Boolean
If KeyAscii <> 46 Or InStr(1, Text1.Text, ".") > 0 Then
NotDecimal = True
Else
NotDecimal = False
End If
End Function
Last edited by akki; Feb 13th, 2004 at 01:15 AM.
akki
-
Feb 13th, 2004, 01:15 AM
#5
Hyperactive Member
Or Try this
VB Code:
Public Function CheckNoAlphas(KeyAscii As Integer, Optional Existing As String, Optional SelStart As Integer) As Integer
On Error Resume Next
'allow control keys through
If KeyAscii = vbKeyReturn Or KeyAscii = vbKeyDelete Or KeyAscii = vbKeyEscape Or KeyAscii = vbKeyBack Then
CheckNoAlphas = KeyAscii
Exit Function
End If
'block non numerics
If Not IsNumeric(Chr(KeyAscii)) Then
KeyAscii = 0
MsgBox "Enter numbers only", , "Numbers Only"
Else
CheckNoAlphas = KeyAscii
End If
End Function
I call it from the keyPress event.
The problem you need to solve is allowing decimals and delete key strokes
Good Luck
FW
-
Feb 13th, 2004, 01:32 AM
#6
Thread Starter
Fanatic Member
hey thanks to you all...your code works fine....(akki)
however cuz i have 'force' user to key in something in the txtboxes.... : if txtboxes.text= " " then
MsgBox "xxxx"
Exit Sub
....
however i dunno why suddenly all the Sub auto change to Function....and erors pop out....
-
Feb 13th, 2004, 01:37 AM
#7
Addicted Member
mhhh.... could not get your error correctly.... where r u checking if txtboxes.text= " " ?
Posting your code may help !!
-
Feb 13th, 2004, 01:40 AM
#8
Thread Starter
Fanatic Member
the checking is done on a click button where the values from the txtbox is extracted and manipulaiton calculation.... ...is abit long for the codes...cuz there are many txtboxs actually...and different combinations...sorrie..abt that
-
Feb 13th, 2004, 01:43 AM
#9
Addicted Member
is "txtboxes" name of your textbox? is it a control array?
-
Feb 13th, 2004, 01:50 AM
#10
Thread Starter
Fanatic Member
yup txtbox.text is the name of the textbox
-
Feb 13th, 2004, 07:05 AM
#11
Those wont work with right click>paste
Have to rush right now...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|