Results 1 to 6 of 6
  1. #1
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    9,117
    Reputation
    1096
    Thanks
    1,970
    My Mood
    Doh

    [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

  2. #2
    T0P-CENT's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Posts
    88
    Reputation
    14
    Thanks
    17
    My Mood
    Stressed
    Quote Originally Posted by 3Li0 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.Tex*****ntains(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")

  3. #3
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    9,117
    Reputation
    1096
    Thanks
    1,970
    My Mood
    Doh
    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...

  4. #4
    T0P-CENT's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Posts
    88
    Reputation
    14
    Thanks
    17
    My Mood
    Stressed
    Quote Originally Posted by 3Li0 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

  5. #5
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    9,117
    Reputation
    1096
    Thanks
    1,970
    My Mood
    Doh
    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++

  6. #6
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,132
    My Mood
    Dead
    [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.