Link to home
Start Free TrialLog in
Avatar of CRX4LIFE18
CRX4LIFE18

asked on

Adding Hex Values in Visual Basic

Hello,
     I'm looking to add some Hex values in Visual Basic 2005, for example:

0x40+0x08+0x04+0x02 = 0x4E

I need to have 0x4E as a string in the end so I can include it in a label.

But I have not been able to figure out how to do this. I'm sure it's something simple, but I'm lost... Any help would be appreciated, much thanks...

-Matt
Avatar of PaulHews
PaulHews
Flag of Canada image

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim HexArray() As String = {"0x40", "0x08", "0x04", "0x02"}
        Dim IntResult As Integer
        For i As Integer = 0 To HexArray.GetUpperBound(0)
            IntResult += Integer.Parse(HexArray(i).Substring(2), Globalization.NumberStyles.HexNumber)
        Next
        MsgBox(String.Format("Result is {0}", IntResult))

    End Sub
End Class
SOLUTION
Avatar of pkumarra
pkumarra

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CRX4LIFE18
CRX4LIFE18

ASKER

Perfect, thank you very much!!!