Topic Options
#19039 - 09/21/06 11:27 AM VB Script to count total pages in data stream
dstauder Offline
OL User

Registered: 06/28/02
Posts: 74
Loc: St. Louis, Missouri USA
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,

Dan

Top
#19040 - 09/21/06 12:49 PM Re: VB Script to count total pages in data stream
Wonderboy Offline
Junior Member

Registered: 09/14/06
Posts: 15
Loc: Precision
Dan,

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.

http://www.devguru.com/technologies/vbscript/quickref/RegExp_Pattern.html

Hope this helps!
_________________________
Wonderboy!

Top
#19041 - 09/21/06 12:59 PM Re: VB Script to count total pages in data stream
Wonderboy Offline
Junior Member

Registered: 09/14/06
Posts: 15
Loc: Precision
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
Loop

objInputFile.Close
objOutputFile.Close


' 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
_________________________
Wonderboy!

Top
#19042 - 09/21/06 01:23 PM Re: VB Script to count total pages in data stream
cosimo Offline
OL Expert

Registered: 10/31/01
Posts: 1279
Loc: montreal
Hi,

Here is a template that you can use asa guide.

Code:
  
'<%
'********************************************************************
' VBScript that does...
'
'********************************************************************
' Program by:  
' Created:     
' Updated:     N/A
'********************************************************************

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

'********************************************************************
' Main
'********************************************************************
Set fileInput=FSO.OpenTextFile(Watch.GetJobFilename, cRead)
sTempPath=FSO.GetFile(Watch.GetJobFilename).ParentFolder.Path
sTempName=FSO.GetTempName
Set fileOutput=FSO.GetFolder(sTempPath).CreateTextFile(sTempName)

i=0
Do While not(fileInput.AtEndOfStream)
  i=i+1
  sLine=fileInput.ReadLine
  ' Process the read line here...
  fileOutput.WriteLine(sLine)
Loop

fileInput.Close
fileOutput.Close
' 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
Cosimo

Top