decimal to hexadecimal

vb6 Grenada
  • 14 years ago

    i have a decimal number in a variable i want to convert it into hexa decimal
    and i want to assign it into a target varable the problem is my target variable can hold only one byte so i want to to assign this hex number in byte by byte
    that is if a=&h0fe2
    i want to assign b=&h0f
                     c=&he2




    thank you in advance

  • 14 years ago

    Hi Harish
     The follwoing code may helpful for u.
     u can get the length of the following array is 0-5. u can also change it as per ur requirement.

    U also can get the value byte by byte using
    'bytArray.data(0..55)

    Private Const SPMAXQUERYSIZE = 56

    Private Type DATAQUERY
        Data(SP
    MAXQUERYSIZE - 1) As Byte
    End Type



    Private Sub Command1_Click()
    'This converts the query string to a query byte array
        Dim bytArray As DATAQUERY
        '0C65450C
       
        bytArray = StringToDataQuery("0FE2", 4)
    End Sub
    Private Function StringToDataQuery(QueryStr As String, QueryLength As Integer) As DATAQUERY
        Dim ByteIndex As Integer

        For ByteIndex = 0 To QueryLength - 1
        StringToDataQuery.Data(ByteIndex) = Val("&H" + Mid$(QueryStr, ByteIndex * 2 + 1, 2))
        Next ByteIndex

    End Function

    I hope this logic may useful for u

    Regards
    Hari K





































  • 14 years ago
    thank u hari i will try it out

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone” - Bjarne Stroustrup