Discussion Locked

VB6 - Read in string including nulls?

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I'm trying to convert a mainframe created file to a text file - removing the escape sequences. One escape sequence uses the null (hex 00) but when I read into a variable with Line Input the null character is lost. What method can I use to retain the null so I can look for it and replace it?

9 replies

by jackofalltech

Two solutions:
First, is the M/F file text only? If so, you should transfer it with the ASCII option which would remove/translate the null bytes for you.
The other option is to open the file in binary mode, read a block of bytes into an array and scan for the CR/LF.

Ralph

by wessir

M/F ? What's the ASCII option? I got around the problem by translating the file to a new file in binary mode, replacing the null with another character which I could then operate with. Is there a better way?

by tduval

Don't read strings, Ie reading into memory until 0x0d/0x0a.
Read char by char, until EOF (End Of File).
So, you'll be able to manage any character read.

by jackofalltech

OK, Sorry, I'll try again. What method are you using to transfer the file from the mainframe (M/F) to the PC? You have the choice of Binary or ASCII mode. In either an FTP or a 3270 client you should be able to specify parameters for the IND$ program to tell it to translate EBCDIC to ASCII including CR/LF (CarriageReturn/LineFeed).
Give us some more info and we'll be able to help you.

Ralph

by wessir

I don't control how the file is output. I get it from the customer as ASCII. I work in a print shop so we often get files from customers in whatever format they can provide. In this case the file is what would have been sent directly to the printer but redirected to a file. I don't know what mechanism made that happen. I am usually dealing with novice users who can't give me any details. For this problem all they can tell me is the printer that the file was built for no longer exists. My workaround was to convert the null characters to an unused character in binary mode. Then I handle that new character as a special case inside my program. Is there a better way?

by rrv

As i have experience with ASCII and EBCDIC i have solution. First thing is to set your CCSID in both windows and MF environment to 37 (US). Then use either ADODB or FileSystemObject from VB to retieve your file from MF. Use Replace function in VB to replace all nulls [vbNull - Constant] to spaces. This logic works fine.

RV

by wessir

That's all greek to me. I ended up reading the file binary and replacing the nulls with another character and putting to a new text file.

This discussion is closed to new replies.