I have this requirement to export data to a file. The 1st 10 characters in the file has to have information which is used by an external application.
This information is the BYTE value of the date / time + some additional flags from the system.
The requirement is straight forward when the data that is to be converted is non zero, and I can use the num2char function.
The problem i have is when the data that is to be converted is non zero, num2char returns a blank (null?) string. This is not written to the export file.
I tried using BinaryIO to write files, but this creates a file that is not suitable to me as the output file is structured in a particular way, and I believe that BinaryIO creates a file inits own native format.
The only other option will be to use a DLL developed in .Net that will do the same, but I need to use this as a last resort.
I am posting a sample Job below, that will use both BinaryIO, and AsciiIO. The expected output should be a file with exactly 10 characters. However, I never get more that 8 in the Ascii file because of the last two zeros, and some unusable data in the Binary file.
Any suggestions are welcome.
static void ___BinaryExport(Args _args)
{
#file
BinaryIo binaryFile;
AsciiIO asciiFile;
Filename _fileName;
Binary binaryHeader;
System.Byte byteVersion;
System.Byte byteDay;
System.Byte byteMonth;
System.Byte byteYear;
System.Byte byteHour;
System.Byte byteMinute;
System.Byte byteSecond;
System.Byte byteType;
System.Byte byteEncrypted;
System.Byte byteCompressed;
int i;
utcDateTime rightNow = datetimeutil::utcNow();
;
binaryHeader = new Binary(10);
//datetimeutil::day(rightNow);
binaryHeader.byte(0,1); //1 : Header is Always 1
binaryHeader.byte(1,datetimeutil::day(rightNow)); //2 : Day part of Date
binaryHeader.byte(2,datetimeutil::month(rightNow)); //3 : Month part of Date
binaryHeader.byte(3,datetimeutil::Year(rightNow)); //4 : Year part of Date
binaryHeader.byte(4,datetimeutil::hour(rightNow)); //5 : Hour part of Date
binaryHeader.byte(5,datetimeutil::minute(rightNow));//6 : Minute part of Date
binaryHeader.byte(6,datetimeutil::second(rightNow));//7 : Second part of Date
binaryHeader.byte(7,1); //8 : Comes from Parameter
binaryHeader.byte(8,0); //9 : Is Encrypted? 0 for No, 1 for Yes
binaryHeader.byte(9,0); //10: Is Compressed? 0 for No, 1 for Yes
_filename = “C:\Interface\Temp\Bin001.xhd”;
binaryFile = new BinaryIo(_filename, #io_write);
for (i=0; i<=9; i+=1)
{
binaryFile.writeExp([binaryHeader.string(i)]);
//binaryFile.writeExp([binaryHeader.string(i)]);
}
_filename = “C:\Interface\Temp\Asc001.xhd”;
asciiFile = new asciiIo(_filename, #io_write);
for (i=0; i<=9; i+=1)
{
asciiFile.writeChar( binaryHeader.byte(i) );
}
}