[Help]Determining if a string contains numbers.[Solved]

Posts 1–6 of 6 · Page 1 of 1
[Help]Determining if a string contains numbers.[Solved]
hello, i want to make a function which checks if a value is a number or not....
i've got this;

Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        For i As Integer = 0 To Integer.MaxValue
            If TextBox2.Text = CType(i, String) Then
                GoTo er
                Exit Sub
            Else
                i = 1
                TextBox3.Text = TextBox3.Text.Replace("//Created by Table Viewer v1.0 Beta", " " & ComboBox1.Text & " " & TextBox2.Text & ";" & vbNewLine & "//Created by Table Viewer v1.0 Beta")
                Exit For
            End If
        Next
er:
        MsgBox("The value name can't be an integer!", MsgBoxStyle.Exclamation, "Error")
    End Sub
But when I try it, and insert a number in the textbox it shows the message box but it adds the value to a list too I don't want it to the list
Quote Originally Posted by user590177 View Post
hello, i want to make a function which checks if a value is a number or not....
i've got this;

Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        For i As Integer = 0 To Integer.MaxValue
            If TextBox2.Text = CType(i, String) Then
                GoTo er
                Exit Sub
            Else
                i = 1
                TextBox3.Text = TextBox3.Text.Replace("//Created by Table Viewer v1.0 Beta", " " & ComboBox1.Text & " " & TextBox2.Text & ";" & vbNewLine & "//Created by Table Viewer v1.0 Beta")
                Exit For
            End If
        Next
er:
        MsgBox("The value name can't be an integer!", MsgBoxStyle.Exclamation, "Error")
    End Sub
But when I try it, and insert a number in the textbox it shows the message box but it adds the value to a list too I don't want it to the list
Code:
For I As Integer = 0 To 9
            If TextBox1.Text.Contains(I) Then
                MsgBox("The value name can't be an integer!", MsgBoxStyle.Exclamation, "Error")
                Exit Sub
            End If
        Next
ComboBox1.Text & " " & TextBox2.Text & ";" & vbNewLine & "//Created by Table Viewer v1.0 Beta")
Quote Originally Posted by T0P-CENT View Post
Code:
If Not IsNumeric(TextBox1.Text) Then
TextBox3.Text = TextBox3.Text.Replace("//Created by Table Viewer v1.0 Beta", " " & ComboBox1.Text & " " & TextBox2.Text & ";" & vbNewLine & "//Created by Table Viewer v1.0 Beta")
Else
MsgBox("The value name can't be an integer!", MsgBoxStyle.Exclamation, "Error")
End If
omg!
It's kinda embarrassing, didn't come at my mid
thanks anyways...
Quote Originally Posted by user590177 View Post
omg!
It's kinda embarrassing, didn't come at my mid
thanks anyways...
check the code again , i edited it isnumeric for somehow when i try a1 or any no. it passes
Quote Originally Posted by T0P-CENT View Post
check the code again , i edited it isnumeric for somehow when i try a1 or any no. it passes
no, no, no I don't want to add:
Only Numeric Values, but if they are values like:
A554ACE, it doesn't really matter, I'm making a Table viewer for reversing structs in C++
[highlight=vbnet]Dim i as string = "329495498"
If Microsoft.VisualBasic.IsNumeric(cint(i)) Then
TextBox3.Text = TextBox3.Text.Replace("//Created by Table Viewer v1.0 Beta", " " & ComboBox1.Text & " " & TextBox2.Text & ";" & vbNewLine & "//Created by Table Viewer v1.0 Beta")
Else
MsgBox("The value name can't be an integer!", MsgBoxStyle.Exclamation, "Error")
End If [/highlight]

Should be like that. If you want to check if the string is alphanumeric (contains alphabets and numbers) then use the following function:

First add this:

[highlight=vbnet]Public Function IsNumeric(ByVal [String] As String) As Boolean
For i As Integer = 0 To [String].Length - 1
If Not (AscW([String].Substring(i, 1)) >= 48 AndAlso AscW([String].Substring(i, 1)) <= 57) Then 'asc value range of numbers
Return False
End If
Next
Return True
End Function[/highlight]

Then this:

[highlight=vbnet]Public Function IsAlphaNumberic(ByVal [String] As String) As Boolean
For i As Integer = 0 To [String].Length - 1
If Not (IsNumeric([String].Substring(i, 1)) OrElse _
(AscW([String].Substring(i, 1)) >= 65 AndAlso AscW([String].Substring(i, 1)) <= 90) OrElse _
(AscW([String].Substring(i, 1)) >= 97 AndAlso AscW([String].Substring(i, 1)) <= 122)) Then
Return False
End If
Next
Return True
End Function
[/highlight]

Then call the IsAlphaNumeric function to check:

[highlight=vbnet]If IsAlphaNumeric("ABC123") Then
Msgbox ("")
Else
Msgbox ("/shofo")
End If [/highlight]

Taken from my post in snippets vault.
Posts 1–6 of 6 · Page 1 of 1
This thread is closed for replies.

Tags for this Thread

None

Talk with us