Click to See Complete Forum and Search --> : Convert a Binary File To Ascii String


VIPER_GTS-
February 8th, 2000, 06:19 AM
Dear All:

I have a problem on converting a binary file to a Ascii String.
The following is a sub to convert an input binary String to ascii string but I found that
it does not working
Can someone point out where did I do wrong???

Thanks in advance


public Sub Bin2Asc(strBin as string, strAsc as string)
Dim lLen as Long, i as Long, strBin2 as string
lLen = len(strBin)
strAsc = ""
for i = 1 to lLen
Dim strTmp as string
Dim btByte as Byte
strTmp = Hex(Asc(mid$(strBin, i, 1)))
If len(strTmp) < 2 then
strTmp = "0" & strTmp
else
If len(strTmp) = 4 then
lLen = lLen - 1
End If
strAsc = strAsc + strTmp
If i = lLen then
Exit for
End If
next i
End Sub

February 8th, 2000, 10:10 AM
what you did wrong was that you used a ASCII->Binary function to convert Binary-> ASCII. The name of the function should have been Asc2Bin, because this will take any string and convert it to another string double the size containing the hex codes of all the chars.

VIPER_GTS-
February 8th, 2000, 07:30 PM
Whoops!
Sorry about the naming problem, this sub should call Asc2Bin.
Assume I have a text file contain the follow hex value
30 80 2A 86 48 86 F7 0D 01
^^^^^^^^^^^
This sub will read all the hex value one by one collectly except it will read 2 byte at once for the &H8648 and &H86F7.

I tried to use other conversion function like AscB.. etc, but they just doesn't work.
Can someone give me a hint?

Thanks in advance.