|
-
Sep 13th, 2005, 12:49 PM
#1
Thread Starter
Fanatic Member
Exit Sub if string = number
Hello,
I have a text box and a command button, what is the code to make sure that the text of the text box is not a number when I click the command button?
-
Sep 13th, 2005, 12:57 PM
#2
Fanatic Member
Re: Exit Sub if string = number
VB Code:
Private Sub Command1_Click()
If IsNumeric(Text1.Text) = True Then
Exit Sub
End If
End Sub
This might be what you are looking for.
Using VB6 or VB.net 2008 with .net 3.5
"Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad
-
Sep 13th, 2005, 12:58 PM
#3
Re: Exit Sub if string = number
This will work if the number is greater than 0 only.
VB Code:
Private Sub Command1_Click()
If Val(Text1.Text) > 0 Then
MsgBox "Valid Number"
End If
End Sub
-
Sep 13th, 2005, 01:00 PM
#4
Re: Exit Sub if string = number
This will find a number anywhere within the textbox string.
VB Code:
Private Sub Command1_Click()
Dim EachCharacter As String * 1
Dim MyNumber As Integer
Dim i As Long
For i = 1 To Len(Text1.Text)
EachCharacter = Mid(Text1.Text, i, 1)
If IsNumeric(EachCharacter) Then 'its a number
MsgBox "No numbers allowed"
Exit For
End If
Next
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|