Solved

VB Type Mismatch Error in Textbox

Posted on 2003-11-06
6
695 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
6 Comments
 
LVL 48

Expert Comment

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

Expert Comment

by:dancebert
ID: 9695406
0
 
LVL 48

Accepted Solution

by:
Mikal613 earned 230 total points
ID: 9695445
if not isnumeric(trim(textbox.text)) then
 msgbox "Sorry!!"
End if
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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 85

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 85

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

831 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