Products | About Us

Problem with scripting

Got a problem. The FSO has problems with binary files with ascii00 codes. I'm trying to use ADOdb and it gives me a syntax error in the script at line 149 which is the statement: BinaryStream.LoadFromFile FileName in the ReadBinaryFile function. This script works fine run in wsh. Help?

option Explicit
'on error resume next

dim xeroxLiability, xeroxYellow, xeroxBilling, xeroxPlain ' xerox tray numbers
dim kodakLiability, kodakYellow, kodakBilling, kodakPlain ' kodak tray numbers

dim cTray1, cTray2, cTray3, cTray4 ' Calligo Tray codes
dim kTray1, kTray2, kTray3, kTray4 ' Replacement Kodak Tray Codes.

dim startTray, endTray ' standard escape sequences
dim newStartTray, newEndTray ' standard escape sequences

newStartTray = chr(27) + chr(38) + chr(108) ' hex: 1B + 26 + 6C (esc&1)
newEndTray = "H" ' literal H

startTray = "\x1B\x26\x6C" ' pattern for hex: 1B + 26 + 6C (esc&1)
endTray = "[H]" ' literal H

xeroxLiability = "[1]" ' original
xeroxYellow = "[2]" ' xerox
xeroxBilling = "[3]" ' tray
xeroxPlain = "[4]" ' codes

kodakLiability = "A" ' replacement
kodakYellow = "B" ' kodak
kodakBilling = "C" ' tray
kodakPlain = "D" ' codes

' build strings to find, original Calligo Xerox codes

cTray1 = startTray + xeroxLiability + endTray
cTray2 = startTray + xeroxYellow + endTray
cTray3 = startTray + xeroxBilling + endTray
cTray4 = startTray + xeroxPlain + endTray

' build strings to replace, new Kodak tray codes

kTray1 = newStartTray + kodakLiability + newEndTray
kTray2 = newStartTray + kodakYellow + newEndTray
kTray3 = newStartTray + kodakBilling + newEndTray
kTray4 = newStartTray + kodakPlain + newEndTray


'wscript.echo "ctray1=", cTray1
'wscript.echo "ctray2=", cTray2
'wscript.echo "ctray3=", cTray3
'wscript.echo "ctray4=", cTray4

'wscript.echo "kTray1=", kTray1
'wscript.echo "kTray2=", kTray2
'wscript.echo "kTray3=", kTray3
'wscript.echo "kTray4=", kTray4



'dim targetFolder1, targetFolder2, infile
'
'targetFolder1 = WScript.Arguments.Item(0)
'targetFolder2 = WScript.Arguments.Item(1)
'infile = WScript.Arguments.Item(2)
'

Dim objFso, objFile, printFilePath, printFileOut, printLineB, printLineB2, printLine

Set objFso = CreateObject("Scripting.FileSystemObject") ' create filesystem object

' printFilePath = "test.prn"
printFileOut = "out_" + printFilePath

Dim Repl, objRegExp, printFileLine
Set objRegExp = New RegExp ' New Regular expression to perform search/replace

objRegExp.IgnoreCase = False ' Ignore Case of Text
objRegExp.Global = True ' Global replace
'wscript.echo "Start ReadBinary"
printLineB = ReadBinaryFile(printFilePath) ' read binary copy of print file

'wscript.echo "start binarytoString"

printLine = ByteArray2Text(printLineB)


'wscript.echo "start edits"
' perform edits, replace tray codes

objRegExp.Pattern = cTray1 ' find Calligo/Xerox Tray 1
repl = kTray1 ' replace with kodak tray 1

printLine = objRegExp.Replace(printLine,repl) ' perform the find and replace

objRegExp.Pattern = cTray2 ' find Calligo/Xerox Tray 2
repl = kTray2 ' replace with kodak tray 2

printLine = objRegExp.Replace(printLine,repl) ' perform the find and replace

objRegExp.Pattern = cTray3 ' find Calligo/Xerox Tray 3
repl = kTray3 ' replace with kodak tray 3

printLine = objRegExp.Replace(printLine,repl) ' perform the find and replace

objRegExp.Pattern = cTray4 ' find Calligo/Xerox Tray 4
repl = kTray4 ' replace with kodak tray 4

printLine = objRegExp.Replace(printLine,repl) ' perform the find and replace

'wscript.echo "start string to binary"
'printLineB2 = stringtoMultiByte(printLine)
printLineB2 = asciiStringtoBinary(printLine)

'wscript.echo "start savebinarydata"
saveBinaryData printFileOut,printLineB2

dim objFileIn, objFileOut
Set objFileIn = objFso.getfile(printFilePath)
Set objFileOut = objFso.getfile(printFileOut)

'wscript.echo "objFileIN.name=", objFileIn.name
'wscript.echo "objFileOut.name=", objFileOut.name

objFileIn.name = printFilePath + ".input"
objFileOut.name = printFilePath


' objFSO.DeleteFile printFilePath

' objFSO.MoveFile printFileOut, PrintFilePath

' free resources
set objRegExp = nothing
set objFileIn = nothing
set objFileOut = nothing
set objFSO = nothing


Function ReadBinaryFile(FileName)
Const adTypeBinary = 1

'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")

'Specify stream type - we want To get binary data.
BinaryStream.Type = adTypeBinary

'Open the stream
BinaryStream.Open

'Load the file data from disk To stream object
BinaryStream.LoadFromFile FileName

'Open the stream And get binary data from the object
ReadBinaryFile = BinaryStream.Read

set BinaryStream = nothing
End Function

Function SaveBinaryData(FileName, ByteArray)
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2

'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")

'Specify stream type - we want To save binary data.
BinaryStream.Type = adTypeBinary

'Open the stream And write binary data To the object
BinaryStream.Open
BinaryStream.Write ByteArray

'Save binary data To disk
BinaryStream.SaveToFile FileName, adSaveCreateOverWrite

set BinaryStream = nothing
End Function

Function ByteArray2Text(varByteArray) 'Convert byte array into a string with ADODB.Recordset
Dim rs
Const adLongVarChar = 201
Set rs = CreateObject("ADODB.Recordset")
rs.Fields.Append "temp", adLongVarChar, LenB(varByteArray)
rs.Open
rs.AddNew
rs("temp").AppendChunk varByteArray
rs.Update
ByteArray2Text = rs("temp")
rs.Close
Set rs = Nothing
End Function

function asciistringtobinary(str)
dim binobj
dim ahex(),oparser,oelem, i
redim ahex(len(str)-1)
for i=0 to len(str)-1
ahex(i)=right("00" & hex(asc(mid(str,i+1,1))),2)
next
set oparser=createobject("msxml2.domdocument")
with oparser
set oelem=.createElement("x")
oelem.datatype="bin.hex"
oelem.text=join(ahex,"")
binobj=oelem.nodetypedvalue
end with
set oelem=nothing
set oparser=nothing
asciistringtobinary=binobj
end function

Harvey Kaye
18th Oct 2008

Harvey,

I can't see where you have declared the variable FileName.

Did you mean to use PrintFilePath instead?

Tony Edgecombe
19th Oct 2008

Filename is declared in the function header:
Function ReadBinaryFile(FileName)

Harvey Kaye
21st Oct 2008

Harvey,

Sorry I missed that.

What build of Print Distributor are you running?

Tony Edgecombe
21st Oct 2008

Sorry should have included that. Build 4.2.2061

Harvey Kaye
21st Oct 2008

Harvey,

I think the problem is if you are running inside the script editor PrintFilePath won't be set.

You need to click on the fields button in the script editor and you enter a value for the PrintFilePath which is used just for testing.

Also you are going to have a problem with the line printFileOut = "out_" + printFilePath as the path will have a drive letter at the begining so printFileOut will start "out_C:\..."

Tony Edgecombe
22nd Oct 2008

Noted, we were using the fields button.

I also have noted the problem with file rename and have used a different approach.

I have also noted today the error log does not report the queue with the problem, it just gives date/time and the message. It would be nice if it reported the virtual printer name, example:

23/10/2008 08:56 Syntax error in line: 130 column: 9
in .\source\actions.cpp at 1715

How can I tell which printer this is? Is there no way to report the actual VB error as opposed to reporting everything as "syntax error"? Thanks.

Harvey Kaye
23rd Oct 2008

I'll look into the error reporting, I think we can probably improve the message.

Improved logging is on my todo list.

Are you still having the original problem or has that been resolved?

Tony Edgecombe
23rd Oct 2008

I got around the original problem by:

* copy & paste to notepad the script and save it.
* uninstalling the product completely
* reinstalling it
* reinstalling the queues
* repasting the script.

It seemed the whole product was hosed at the point I was having that error, and it was the only option. I tried removing the queue & rebuilding it to no avail. Rebooting didn't help. I couldn't even get it to do simple reprint.

Harvey Kaye
23rd Oct 2008

Did you have the service running under a different account? The only thing i can think that would change after a reinstall is the service account will be reset to default.

Tony Edgecombe
24th Oct 2008

I don't think so.

Harvey Kaye
27th Oct 2008

This thread is closed to new posts.

Feed