• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 158
  • Last Modified:

String to Hexadecimal conversion

Hello All,

Is there any fucntion available in VB6 to convert String to Hex.
0
medhaonline
Asked:
medhaonline
  • 2
1 Solution
 
DhaestCommented:
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
 
sazhagianambiCommented:
Hex("Expression") is used to convert Hex Value.

Expression Maybe Valid Number Or Expression

(Ie) Hex(23)
     Hex("23") Both is allowed
0
 
sazhagianambiCommented:
Convert Every Char Of String into a Ascii and use hex()

Nambi
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now