tags:

views:

165

answers:

1

Hi, I am trying to convert a file from binary to text, by simply replacing each character with the hexadecimal code. For example, character 'c' will be replaced by '63'.

I have a code which is working fine in normal systems, but it breaks down in the PC where I need to use it as it has default locale set to Chinese.

I am using the following statements to read a byte -

ch$ = " "
Get #f%, , ch$

I suspect there is a problem when I am reading the file byte by byte, as it is skipping certain bytes because they form composite characters. It's probably reading 2 bytes which form an Asian character as one byte. It is thus forming a much smaller file than the expected size.

How can I read the file byte by byte?

Full code is pasted here: http://pastebin.com/kjpSnqzV

+2  A: 

Your suspicion is correct. VB file reading automatically converts strings into Unicode from the default code page on the PC. On an Asian code page, some characters are represented as more than one byte.

I advise you to use a Byte variable rather than a string - that will stop VB being over helpful.

Dim ch As Byte  
Get #f%, , ch  

Another possible problem with the original code is that some byte sequences are illegal on Asian code pages (they don't represent valid characters). So your code could experience errors for some input files, but presumably you want it to work with any file.

MarkJ