Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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...

qrt
Posted

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...

qrt
Posted

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?

"Reality is fake, Dreams are for real"
Posted
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?

"Reality is fake, Dreams are for real"
  • *Experts*
Posted

&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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...