VB Script to count total pages in data stream

Posted by: dstauder

VB Script to count total pages in data stream - 09/21/06 11:27 AM

I am looking to count the number of pages in the data stream and place that number in a job info. I know that I have to run a VB Script in a Watch process to accomplish this task. There is an object that shows up once on each page. If I could count the number of occurances of this bit of data I should get my total number of pages. If anyone has a script that can do this it would be helpful.

Thanks in advance,

Posted by: Wonderboy

Re: VB Script to count total pages in data stream - 09/21/06 12:49 PM


I have written a script similar to what you are asking. I luckily had a static text trigger for each page to count as I looped through the data. If you know the number of lines per page you could go that route or you could try to count the number of form feeds in the data with the VBScript RegExp. Here is a link that may help you out.


Hope this helps!
Posted by: Wonderboy

Re: VB Script to count total pages in data stream - 09/21/06 12:59 PM

This is the script looking for the static text trigger!

' Simple VBScript that will count the number of lines to determine the
' number of pages within the document.

' NOTE - There is no variable passed for a form feed so we will be going
' a static text identifier.

' Variable declaration
Option Explicit
Dim objFSO, objInputFile, objOutputFile
Dim strTempName, strTempPath, strLine

Dim lineCount, pageCount, firstTime, hasStars
pageCount = 0 'Counter for the number of pages

Set objFSO = CreateObject("Scripting.FileSystemObject")

'Variable for the input file name
Dim m_FileName
m_FileName = PW_GetJobFileName

' Main
' Create the input text file object
Set objInputFile = objFSO.OpenTextFile(m_FileName, 1)

' Get the temp path
strTempPath = objFSO.GetFile(m_FileName).ParentFolder.Path

' Get the temp file name
strTempName = objFSO.GetTempName

' Create an opened temp output file
Set objOutputFile = objFSO.GetFolder(strTempPath).CreateTextFile(strTempName)

' First need to loop through the file to count the number instances of the trigger
Do While objInputFile.AtEndOfStream <> True
strLine = objInputFile.Readline

If (InStr(1, strLine, "SOME TEXT TRIGGER", 1)) Then
pageCount = pageCount + 1 'Incrimenting the page counter
End If


' Replace the input file by the output file
objFSO.DeleteFile m_FileName, true
objFSO.MoveFile strTempPath & "" & strTempName, m_FileName

' Setting the jobInfo variables
' jobInfo 8 = pageCount
watch.setjobinfo 8,pageCount
Posted by: cosimo

Re: VB Script to count total pages in data stream - 09/21/06 01:23 PM


Here is a template that you can use asa guide.

' VBScript that does...
' Program by:  
' Created:     
' Updated:     N/A

' Variable declaration
Option explicit
Const cRead=1, cWrite=2, cAppend=8
set FSO=CreateObject("Scripting.FileSystemObject")
Dim fileInput, fileOutput
Dim sTempPath, sTempName
Dim sLine
Dim i

' Main
Set fileInput=FSO.OpenTextFile(Watch.GetJobFilename, cRead)
Set fileOutput=FSO.GetFolder(sTempPath).CreateTextFile(sTempName)

Do While not(fileInput.AtEndOfStream)
  ' Process the read line here...

' Delete the input file and rename the changed file
FSO.DeleteFile Watch.GetJobFilename, true
FSO.MoveFile sTempPath+"\"+sTempName, Watch.GetJobFileName

' Set a Watch jobinfo with the total of lines read
Watch.SetJobInfo 9,i
Hope this helps