Solved

VB Type Mismatch Error in Textbox

Posted on 2003-11-06
6
691 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now