Results 1 to 7 of 7

Thread: Hex$ - equivilent in C#?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Hex$ - equivilent in C#?

    ok so im trying to port over some horrible code into C# but I am not sure exactly how to convert something like tihs:

    Hex$(someInputString)

    what would this be in C#?

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Hex$ - equivilent in C#?

    you need to add a reference to Microsoft.VisualBasic, then:

    Microsoft.VisualBasic.Conversion.Hex(number)

  3. #3
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: Hex$ - equivilent in C#?

    Paul's answer will guarantee the same result under all conditions since it is the same function being called.
    If you want the equivalent without using the Microsoft.VisualBasic assembly, then use:
    Code:
    Convert.ToString(someInputString, 16).ToUpper()
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Hex$ - equivilent in C#?

    Thanks - yes exactly, do NOT want to add any references to VB assembly.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  5. #5
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Hex$ - equivilent in C#?

    He could always translate it to Hex when converting it to a string in 1 move:
    vb Code:
    1. Dim Numb As Integer = 255
    2. MessageBox.Show(Numb.ToString("X"))
    The vb code for this is the same too: C# convert integer to hex and back again - Stack Overflow
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Hex$ - equivilent in C#?

    yeh, I have that for some areas of the code so thats great. but when we have a string input which needs to be converted using the Hex$ in VB6, there is no equiv in C#:

    ok so the problem is.... there is no overload for string and an int. but the input data is a string.

    Convert.ToString(aStringHere, 16).ToUpper() - will not work

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  7. #7
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: Hex$ - equivilent in C#?

    Sometimes you have to be creative to get around these limitations:
    Code:
    System.Convert.ToString(System.Convert.ToInt32(aStringHere), 16).ToUpper()
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

Posting Permissions

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



Click Here to Expand Forum to Full Width