working with 2 streams

ryanmckeever

New Member
Hope you are well...
I'm trying to develop some code which reads in a PRN file (generated by printing to a file in Bartender)

I have some replacement variable in here e.g. %pallet%
I replace these and write to a intermediate file
This works fine...

The problem is...
I have pretty much exactly the same PRN as before except I now have an image which has been encoded in the PRN file

When I run the code (see below) now it seems that the encoded image has been converted to straightforward text.

Anyone any ideas how to handle mixed text and binary type data?


OUTPUT STREAM ubi-501 TO VALUE(param08.matrix-nt_port).
INPUT STREAM file_input FROM VALUE(param08.label-spooler).
REPEAT:
IMPORT STREAM file_input UNFORMATTED cLine.
IF cline MATCHES "*%Factory%*"
THEN
cLine = REPLACE(cLine,"%Factory%",param08.label-prog).
IF cline MATCHES "*%Pallet%*"
THEN
cLine = REPLACE(cLine,"%Pallet%",STRING(pallet.unique_pallet,'9999999999')).
IF cline MATCHES "*%Date%*"
THEN
cLine = REPLACE(cLine,"%Date%",STRING(pallet.scan_date)).
IF cline MATCHES "*%PalletBar%*"
THEN
cLine = REPLACE(cLine,"%PalletBar%",STRING(s-co,'999') + STRING(pallet.unique_pallet,'9999999999')).

PUT STREAM ubi-501 UNFORMATTED cLine SKIP.
END.
INPUT STREAM file_input CLOSE.
OUTPUT STREAM ubi-501 CLOSE.
 

RealHeavyDude

Well-Known Member
I don't think you can handle this with input and output streams. AFAIK, when you open the stream and you don't specify the binary option everything is treated as text. There is no way for the 4GL to know what should be treated as text and what should be treated as binary. By default, unless you specify the NO-CONVERT option there is also a conversion from the -cpstream setting to the -cpinternal setting taking place. You could try using the NO-CONVERT option, but I don' think it'll work.

I've never done something like this before. But the only idea I can come up with is to load the file into a memory pointer, parse this memory pointer byte by byte, change the desired bytes, and write the memory pointer back to the file.


Regards, RealHeavyDude.
 

mrobles

Member
Hi

I used similar code with RTF files replacing variables.
Due is real text, if it has images works well, but this code does not work with prn files including images even using BINARY NO-CONVERT.
 
Top