home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 September / Chip_2002-09_cd1.bin / zkuste / vbasic / Data / Utils / XZipComp.exe / XceedEncryption.Cab / F112968_Utility.bas < prev    next >
Encoding:
BASIC Source File  |  2001-06-05  |  993 b   |  40 lines

  1. Attribute VB_Name = "Utility"
  2. Option Explicit
  3.  
  4. ' Convert the variant specified to an hexadecimal representation, only if
  5. ' the variant is an array.
  6. Public Function BinaryToHex(ByRef vaBinaryValue As Variant) As String
  7.  
  8.     Dim I As Long
  9.     Dim sNewValue As String
  10.     
  11.     sNewValue = ""
  12.     
  13.     If (VarType(vaBinaryValue) And vbArray) = vbArray Then
  14.         For I = 0 To LenB(vaBinaryValue) - 1
  15.             sNewValue = sNewValue & Right("0" & Hex(CLng(vaBinaryValue(I))), 2)
  16.         Next I
  17.     End If
  18.     
  19.     BinaryToHex = sNewValue
  20.  
  21. End Function
  22.  
  23. ' Convert the hexadecimal string to a byte array return as a variant
  24. Public Function HexToBinary(ByRef sHexValue As String) As Variant
  25.  
  26.     Dim I As Long
  27.     Dim NewValue() As Byte
  28.     
  29.     I = 0
  30.     While I < Len(sHexValue)
  31.         ReDim Preserve NewValue(I / 2)
  32.         NewValue(I / 2) = Val("&H" & Mid$(sHexValue, I + 1, 2))
  33.         I = I + 2
  34.     Wend
  35.     
  36.     HexToBinary = NewValue
  37.  
  38. End Function
  39.  
  40.