How To convert Hex to Dec in VB6.0?-VBForums
Results 1 to 6 of 6

Thread: How To convert Hex to Dec in VB6.0?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Netherlands Antilles
    Posts
    66
    Hi Guys,

    I need to know how to convert Hexidecimal into decimal in Vb6.0
    I am receiving data from my comm port in Text and there are some values that are in Hex. but i need the numeric value of them.

    is that a command of module that i can use to do this?
    let me know.

    Thanks in advance.
    EL.

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    I don't think VB has a built-in hex to dec function

    Here's one I just knocked-up:

    Code:
    Public Function HextoDec(HexNum As String) As Long
    Dim lngOut As Long
    Dim i As Integer
    Dim c As Integer
    
    For i = 1 To Len(HexNum)
      c = Asc(UCase(Mid(HexNum, i, 1)))
      Select Case c
      
      Case 65 To 70
        lngOut = lngOut + ((c - 55) * 16 ^ (Len(HexNum) - i))
      
      Case 48 To 57
        lngOut = lngOut + ((c - 48) * 16 ^ (Len(HexNum) - i))
      
      Case Else
      
      
      End Select
    Next i
    HextoDec = lngOut
    End Function
    Mark
    -------------------

  3. #3
    New Member
    Join Date
    May 2012
    Posts
    5

    Re: How To convert Hex to Dec in VB6.0?

    More simple:

    DecNumber& = CLng("&H" & HexNum$)

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    15,654

    Re: How To convert Hex to Dec in VB6.0?

    Wow - and this thread is over 10 years old.

    Do you really want to start with threads this old

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5
    New Member
    Join Date
    May 2012
    Posts
    5

    Re: How To convert Hex to Dec in VB6.0?

    Quote Originally Posted by szlamany View Post
    Wow - and this thread is over 10 years old.

    Do you really want to start with threads this old
    Because I search for this code and lost time, the two threads I answer are old but first in the search of google for this conversion, and for other people not lost time, the last instruction is the best, I test various, and this is simple, fast and totally operative...

    Is the reason, for people that search this conversion, have fast and simple and good solution...

    Sorry for my bad English...

    Pd: Many persons use VB6, is old, but very usseful, I for example have a program in virtual machine - in a oracle sun virtualbox portable - that I sell, and in the virtual machine have a Windows XP 32 bits, and for this operative system, vb6 is fast and a good solution... And in the virtual machine my program run without changes, worked for decades is possible, and I not lost time in the changes of different versions of windows and changes and craps of microsoft...

    Also in virtualbox machine is possible for my sell the program for mac and for linux, good solution without need to create 3 programs... One for each system...

    One of the big problems of the programation is that is impossible arrive to a be master master master because each little time, changes, changes, changes, and the programmer need to create a good software of any thing, not lost your time in known new codes all the time...

    I with the solution of virtualbox portable, is possible for me put all my time in make a better program, not lose all my time in known the stupids and always changes of microsoft...
    Last edited by Javier Reinoso; May 6th, 2012 at 06:45 PM.

  6. #6
    New Member
    Join Date
    Nov 2012
    Posts
    1

    Re: How To convert Hex to Dec in VB6.0?

    It was very useful to me. I still work a lot with VB6 and do some things the old fashioned way.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.