?
Solved

String to Hexadecimal conversion

Posted on 2003-02-26
3
Medium Priority
?
155 Views
Last Modified: 2010-05-01
Hello All,

Is there any fucntion available in VB6 to convert String to Hex.
0
Comment
Question by:medhaonline
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 150 total points
ID: 8031699
Tried it with 2 textboxes (text1 & text2)

Private Sub Command1_Click()
    Text2.Text = HexDisplayOfFile(Text1.Text)
End Sub

Function HexDisplayOfFile(StrInput As String) As String
   Dim Text1, MyChar, FileNum
   ' Read all characters in the string.
   Do While Len(StrInput) > 0
      MyChar = Left(StrInput, 1)
      StrInput = Right(StrInput, Len(StrInput) - 1)
      If MyChar <> "" Then
         ' Convert byte to Hex like 0A, 6B etc..
         Text1 = Text1 & HexOf(Asc(MyChar)) & " "
      End If
   Loop
   HexDisplayOfFile = Text1  ' Return the Hex display string
End Function

Private Function HexOf(ByVal AscNum As Integer) As String
   ' Return the 2 character Hex string of AscNum, prefix extra "0" if necessary
   Dim TStr
   If AscNum > 255 Then AscNum = AscNum Mod 256
   TStr = Hex(AscNum)  ' Convert to Hex
   If Len(TStr) = 1 Then
      ' Attach "0" on the left
      TStr = "0" & TStr
   End If
   HexOf = TStr  ' Return the 2 character Hex string
End Function
0
 
LVL 1

Expert Comment

by:sazhagianambi
ID: 8031772
Hex("Expression") is used to convert Hex Value.

Expression Maybe Valid Number Or Expression

(Ie) Hex(23)
     Hex("23") Both is allowed
0
 
LVL 1

Expert Comment

by:sazhagianambi
ID: 8032028
Convert Every Char Of String into a Ascii and use hex()

Nambi
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question