yarmiaanuj
Member
- Joined
- May 21, 2012
- Messages
- 12
- Programming Experience
- 1-3
I have a string value 'FC' and i want vb.net to assume it as hex so that i can obtain its decimal equivalent '252'. Please help..:miserable:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim b As Long = "&H" & TextBox1.Text 'textbox1.text = FC Dim a As Integer = b TextBox2.Text = CStr(a) 'textbox2.text = 252 End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a As String = TextBox1.Text 'contains a hex number in string form Dim b As Integer = Convert.ToInt32(a, 16) TextBox2.Text = CStr(b) 'displays the decimal equivalent of hex number in textbox1 End Sub
What is your code going to do if the user types "Hello World" into the TextBox?If you don't know for a fact that the String is a valid representation of a hexadecimal number then you can use the Int32.TryParse method and specify the appropriate number style for hex.