Solved

VB Type Mismatch Error in Textbox

Posted on 2003-11-06
6
706 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 230 total points
ID: 9695445
if not isnumeric(trim(textbox.text)) then
 msgbox "Sorry!!"
End if
0
Independent Software Vendors: 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

Technology Partners: 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!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

707 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