article

Allow Numerals Only

Email
Submitted on: 1/22/2015 3:05:00 AM
By: PorkNBeans (from psc cd)  
Level: Beginner
User Rating: By 7 Users
Compatibility: VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 562
 
     After looking here and a few other places for a simple code that allows only numerals and not to allow text to be pasted into a textbox and with no prevail I figured it out. Not a major thing but for beginners this will help them.

 
				'Just Paste This in the change section of the textbox sub


Private Sub txtText1_Change()
'if an error should occur go to the error handler
On Error GoTo txtText1_Change_Err
'if the text entered is not numeric
100 If Not IsNumeric(txtText1.Text) Then
'display the message box warning
102 MsgBox "Only Numerals Are Allowed", vbOKOnly + vbExclamation, "Numerals Only"
End If
Exit Sub
'after handling the error and showing what line the error occured in if any
' then resume the next action

txtText1_Change_Err:
MsgBox Err.Description & vbCrLf & _
"in Project1.Form1.txtText1_Change " & _
"at line " & Erl
Resume Next
End Sub

you could easily have the textbox clear out by adding txt.text ="" but that is so basic I figured no need to add it. Please if theres no code like this and it does indeed help you at least give me a vote for my time sharing this.


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.