Kurt Posted July 28, 2003 Posted July 28, 2003 Is there a more nice/elegant way of converting a string representing a hexadecimal value to an integer value? At the moment I am doing something like... Public Function MakeInt1(ByVal HexValue As String) As Integer Return CType("&H" & HexValue, Integer) End Function Amazingly this works, while the folowing doesn't Public Function MakeInt2(ByVal HexValue As String) As Integer Return Convert.ToInt32("&H" & HexValue) End Function any comments are more then welcome... Quote qrt
Leaders dynamic_sysop Posted July 28, 2003 Leaders Posted July 28, 2003 CInt ? eg : Private Const WS_EX_TRANSPARENT As Integer = CInt(&H20&) Quote
Kurt Posted July 29, 2003 Author Posted July 29, 2003 Yes, it also seems to take a string as argument. private const WS_EX_TRANSPARENT as integer = cint("&H20") I assume Cint(x) and Ctype(x,integer) are equal. The Convert - class must work differently... Quote qrt
Diablicolic Posted August 4, 2003 Posted August 4, 2003 aahhh!! I don't understand :confused: . I tried doing this on Visual Basic...You see what I want is this: Someone types a number into TextBox1 (Hex), and then clicks Button1, and shows the Integer in TextBox2 (Integer). And how could I do vice-versa? Integer --> Hex? Quote "Reality is fake, Dreams are for real"
Leaders dynamic_sysop Posted August 4, 2003 Leaders Posted August 4, 2003 you can do this also , much simpler.... Dim x As Integer = Integer.Parse(&H20&) MessageBox.Show(x) Quote
Diablicolic Posted August 4, 2003 Posted August 4, 2003 you can do this also , much simpler.... Dim x As Integer = Integer.Parse(&H20&) MessageBox.Show(x) Cool!! What does &H20& do? And where could I find the codes like &H20&? And was does Parse do? Quote "Reality is fake, Dreams are for real"
*Experts* Volte Posted August 4, 2003 *Experts* Posted August 4, 2003 &H20& is hex for 32. Integer.Parse takes a string value and converts it to an integer. I'm not so sure that dynamic_sysop's example is exactly what Kurt wants, since &H20& is recognized by VB as a number regardless of being parsed. You need to use Convert.ToInt32() and specify the base.MessageBox.Show(Convert.ToInt32("20", 16))Will show 32. Note you shouldn't include the &H part. Quote
Diablicolic Posted August 4, 2003 Posted August 4, 2003 Now that's from Hex --> Int, how about Int --> Hex Volte? Quote "Reality is fake, Dreams are for real"
*Experts* Volte Posted August 4, 2003 *Experts* Posted August 4, 2003 MessageBox.Show(Convert.ToString(32, 16))Will show "20". Quote
Diablicolic Posted August 4, 2003 Posted August 4, 2003 Sweet! I put that into my notes, thanks! Quote "Reality is fake, Dreams are for real"
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.