+ Reply to Thread
Results 1 to 4 of 4

Using a "Do Until" loop to convert decimal numbers to hexadecimal

  1. #1
    Registered User
    Join Date
    10-13-2014
    Location
    Portland,Oregon
    MS-Off Ver
    2013
    Posts
    2

    Using a "Do Until" loop to convert decimal numbers to hexadecimal

    I am working on program that requires I use a Do-Until Loop to convert a decimal number to hexadecimal number. The following UDF makes Excel freeze up every time I run it, but it works great when I take out the do-until loop. Is there a better way to use a Do-Until Loop in this function?

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 10-13-2014 at 01:44 PM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Using a "Do Until" loop to convert decimal numbers to hexadecimal

    you've placed a reference TO the UDF code inside the UDF itself. Eek, forever loop!

    Your function is a standalone code. Don't edit that. Instead, create another macro that uses the UDF in it's activities... no infinite loop.

    It seems to me the UDF should just be used in a cell as a formula, and you can add your IF/THEN stuff as a normal formula controls.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    10-13-2014
    Location
    Portland,Oregon
    MS-Off Ver
    2013
    Posts
    2

    Re: Using a "Do Until" loop to convert decimal numbers to hexadecimal

    So I removed the UDF's reference's to itself, and the function doesn't work anymore. I don't really understand how it worked in the first place, I just did a lot of trial and error to get it there. I'm not sure exactly how to use a do while loop in this case without using the hex function. Let me know if you have any ideas! Thanks for all you help.
    This is what the function looks like now:

    Function DecHexConverter(DecValue As String) As String
    Dim sTemp As String

    Do Until DecValue = ""
    If DecValue >= 16 Then
    'if greater than 16 then assign quotients and remainders
    sTemp = (DecValue \ 16) & (DecValue Mod 16)

    ElseIf DecValue > 9 And DecValue < 16 Then
    'if between 10 and 15 Assign A-F
    Select Case DecValue
    Case "10"
    sTemp = "A"
    Case "11"
    sTemp = "B"
    Case "12"
    sTemp = "C"
    Case "13"
    sTemp = "D"
    Case "14"
    sTemp = "E"
    Case "15"
    sTemp = "F"
    End Select
    Else
    'If between 0 and 9 no change
    sTemp = DecValue
    End If

    Loop
    DecHexConverter = sTemp

    End Function

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Using a "Do Until" loop to convert decimal numbers to hexadecimal

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here


    I fixed post #1, now it's your turn to fix post #3.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Excel 2007: How to Convert "5/2/2013" to "May" then subtract a Month so it's "Apr"
    By Golom in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-19-2013, 02:00 AM
  2. Removing digits after decimal in "text" numbers
    By jermsalerms in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-21-2006, 01:52 PM
  3. [SOLVED] I want to convert a column of hexadecimal numbers to decimal num
    By xs2sandeep in forum Excel General
    Replies: 2
    Last Post: 04-04-2006, 04:50 AM
  4. convert "37:30:55" to decimal
    By Teaman in forum Excel General
    Replies: 2
    Last Post: 11-04-2005, 10:25 AM
  5. [SOLVED] CONVERT HEXADECIMAL CELL TO DECIMAL NUMBER
    By JAY in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-24-2005, 11:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1