Hex to Long

  • Thread starter Thread starter Jorge Eldis
  • Start date Start date
J

Jorge Eldis

Hi

How to convert this code to C#?

HexToLong(ByVal sHex As String) As Long
HexToLong = Val("&H" & sHex & "&")
End FunctionLa

I have equivalent function but it not return the same value.

static long hextolong(string hexValue)
{

return long.Parse(hexValue,
System.Globalization.NumberStyles.AllowLeadingWhite);

}

Thanks

Jorge Eldis
 
Than you Mark

The code works fine, but I'm still trying to convert other code that has the
suffix "&"

I get this function from microsoft web site:
http://support.microsoft.com/kb/161304

Function HexToLong(ByVal sHex As String) As Long
On Error Resume Next
HexToLong = Val("&H" & sHex & "&")
If Err Then
On Error Goto 0
HexToLong = Val("&H" & sHex)
End If
End Function

if you can advise me, thank you, I will tray to find something on internet.
 
Than you Mark

The code works fine, but I'm still trying to convert other code that has the
suffix "&"

I get this function from microsoft web site:
http://support.microsoft.com/kb/161304

Function HexToLong(ByVal sHex As String) As Long
On Error Resume Next
HexToLong = Val("&H" & sHex & "&")
If Err Then
On Error Goto 0
HexToLong = Val("&H" & sHex)
End If
End Function

if you can advise me, thank you, I will tray to find something on internet.
 
Jorge said:
Than you Mark

The code works fine, but I'm still trying to convert other code that has the
suffix "&"

I get this function from microsoft web site:
http://support.microsoft.com/kb/161304

Function HexToLong(ByVal sHex As String) As Long
On Error Resume Next
HexToLong = Val("&H" & sHex & "&")
If Err Then
On Error Goto 0
HexToLong = Val("&H" & sHex)
End If
End Function

if you can advise me, thank you, I will tray to find something on internet.

My advice has to be not to try to convert VB6 code to C#.

It's possible to add a reference to the Microsoft.VisualBasic library so
that you can use functions like Val in C#, but I have to advice against
that too. Use the methods in the System library instead when possible.
 
Jorge said:
Than you Mark

The code works fine, but I'm still trying to convert other code that has the
suffix "&"

I get this function from microsoft web site:
http://support.microsoft.com/kb/161304

Function HexToLong(ByVal sHex As String) As Long
On Error Resume Next
HexToLong = Val("&H" & sHex & "&")
If Err Then
On Error Goto 0
HexToLong = Val("&H" & sHex)
End If
End Function

if you can advise me, thank you, I will tray to find something on internet.

My advice has to be not to try to convert VB6 code to C#.

It's possible to add a reference to the Microsoft.VisualBasic library so
that you can use functions like Val in C#, but I have to advice against
that too. Use the methods in the System library instead when possible.
 
Back
Top