A Digital Age Deserves A Digital Leader

Variable Question (SOLVED)

Variable Question (SOLVED)

Postby gries818 » Fri Nov 24, 2006 8:56 pm

In VB is there a way to tell if a variable contains numbers or letters??? I want to display an error message if the user enters letters instead of numbers instead of having a program error whenever this happens.

Like

Code: Select all
If VAR contains numbers Then
   TextBox1.Text = VAR * 3
ElseIf VAR contains letters Then
   Dim frm_error as new Error_Message
   frm_error.show


Obviously this is incorrect code, I was trying to make it more clear what I wanted.
Image

Mac OS 10.6.7 - Personal
Ubuntu Server 11.04 - Server
Software Development
User avatar
Posts: 3991
Joined: Wed Jul 07, 2004 6:28 pm

Postby NoReflex » Fri Nov 24, 2006 9:47 pm

In VB6 I used the IsNumeric function of the String object.
You could test it with something like :
Code: Select all
Dim S As String
S = "123gh"
If IsNumeric(S) Then MsgBox "Yes", vbOKOnly
If Not IsNumeric(S) Then MsgBox "No", vbOKOnly
End Sub


If this doesn't work for you or it's not what you need I can post a Sub that verifies the string character by character - like a self made IsNumeric function. Just let me know! :yesnod:

Best wishes,
John!
PRO Level 10
User avatar
Posts: 431
Joined: Wed Nov 17, 2004 8:41 pm
Location: Romania

Postby gries818 » Fri Nov 24, 2006 10:59 pm

That worked, thanks!
Image

Mac OS 10.6.7 - Personal
Ubuntu Server 11.04 - Server
Software Development
User avatar
Posts: 3991
Joined: Wed Jul 07, 2004 6:28 pm

Return to HTML, CSS, and Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

cron
cron