i have a function in a module that requries integer values. these values are set by the user typing in two textboxes on the form. the texboxes contain Hexadecimal data in string form.

function:

Friend Function addNewCode(ByVal Location As Integer, ByVal Opcode As Integer) As Boolean

    If (Not LocStack.Count < 1000) Then
        Form1.TextBox1.AppendText(vbCrLf)
        Form1.TextBox1.AppendText("Cannot add new code. No room Left in queue!")
        Return False
    Else
        LocStack.Push(Location)
        opcStack.Push(Opcode)
        Form1.TextBox1.AppendText(vbCrLf)
        Form1.TextBox1.AppendText("Added New Code " & Hex(Location) & "-" & Hex(Opcode) & " in queue slot " & LocStack.Count - 1 & "!")
    End If

    Return True

End Function

and is called when a button is pressed on the form:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    addNewCode(Convert.ToInt32(TextBox1.Text, 16), Convert.ToInt32(TextBox3.Text, 16))
End Sub

However when the button is clicked, the program throws the following:

FormatException: cannot find recognizable digits

any ideas?

--Tandex (TTTHXC)

System.Convert.ToInt32("9a12c",16)

As long as the first argument is a string representation of a hex value this will work. In the general case, the first argument is a string and the second argument is the base so you could also use this to convert other bases such as

System.Convert.ToInt32("203",8)

which would convert 203 octal to base 10.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.