?
Solved

VB Type Mismatch Error in Textbox

Posted on 2003-11-06
6
Medium Priority
?
713 Views
Last Modified: 2008-02-01
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
Comment
Question by:welburn1010
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 9695394
if not isnumeric(textbox.text) then
0
 
LVL 48

Accepted Solution

by:
Mikal613 earned 920 total points
ID: 9695445
if not isnumeric(trim(textbox.text)) then
 msgbox "Sorry!!"
End if
0
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!

 
LVL 33

Expert Comment

by:hongjun
ID: 9695449
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 9695898
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 9695956
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

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question