[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 724
  • Last Modified:

VB Type Mismatch Error in Textbox

I have a TextBox that should only hold numeric values because there is a calculation eg(TextBox.Text = integer + integer) but if the user enters letters of course i get a type mismatch error because you cant add letters to numbers.

So i want some sort of error checking to check if letters have been enetered into the textbox?

cheers

Welburn1010
0
welburn1010
Asked:
welburn1010
1 Solution
 
Mikal613Commented:
if not isnumeric(textbox.text) then
0
 
Mikal613Commented:
if not isnumeric(trim(textbox.text)) then
 msgbox "Sorry!!"
End if
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
hongjunCommented:
one way is to restrict to only integers input

Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii < 48 Or KeyAscii > 57 Then
        KeyAscii = 0
    End If
End Sub



hongjun
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
If you want only integers in your textbox you can also use the SetWindowLong API.  There is an example here:

http://www.galahtech.com/forums/index.php?showtopic=3080
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
There is a more indepth article on how the API works here:

http://www.mvps.org/vbnet/index.html?http://www.mvps.org/vbnet/api/_consts/constse.htm
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now