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?
Printable View
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?
How about NumberBox by Martin..
try this
http://www.vbforums.com/showthread.p...hreadid=231163
humm..though i dunnno why i cannot open up the exe successfully....Unablr to set the version compatible component...is there other alternatives?
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
Or Try this
I call it from the keyPress event.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
The problem you need to solve is allowing decimals and delete key strokes
Good Luck
FW
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....
mhhh.... could not get your error correctly.... where r u checking if txtboxes.text= " " ?
Posting your code may help !!
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
is "txtboxes" name of your textbox? is it a control array?
yup txtbox.text is the name of the textbox
Those wont work with right click>paste
Have to rush right now...