IMPORTANT ANNOUNCEMENT

These forums were permanently set to read-only mode on July 20, 2022. From that day onwards, no new posting or comment is allowed on the site, but the historical content remains intact and searchable.

A new location for posting questions about PlanetPress Suite is now available:

OL Learn - PlanetPress Classic (opens in new tab)

Topic Options
#57929 - 04/02/21 08:05 AM Sum in a txt file
sygui Offline
OL Expert

Registered: 11/02/10
Posts: 170
I have a script (see below). With it I get the sum of all the lines. How can I get instead the sum of all the lines begining with 32B:

file example:

32B:68.76
BANK X
57C:0000051756
32B:100.89
BANK Y
57C:2458863



Const ForReading = 1
Const ForAppend = 8

mySum = 0

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(Watch.GetJobFileName, ForReading)

Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
mySum = mySum + CLng(strLine)
Loop



objFile.Close

Set objFile = objFSO.OpenTextFile(Watch.GetJobFileName, ForAppend)
objFile.Write ":99N:" & mySum
objFile.Close

Top
#57930 - 04/02/21 08:21 AM Re: Sum in a txt file [Re: sygui]
Jean-Cédric Offline
OL Expert

Registered: 10/03/16
Posts: 681
Loc: Québec, Canada
Const ForReading = 1
Const ForAppend = 8

mySum = 0

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(Watch.GetJobFileName, ForReading)

Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
if(left(strLine,3) = "32B") then
mySum = mySum + CLng(strLine)
End If
Loop



objFile.Close

Set objFile = objFSO.OpenTextFile(Watch.GetJobFileName, ForAppend)
objFile.Write ":99N:" & mySum
objFile.Close
_________________________
♪♫♪♫
99 frigging bugs in my code
99 frigging bugs
Take one down
Code around
127 frigging bugs in my code
♪♫♪♫

Top
#57931 - 04/02/21 09:21 AM Re: Sum in a txt file [Re: sygui]
sygui Offline
OL Expert

Registered: 11/02/10
Posts: 170
great thks

Top
#57932 - 04/02/21 09:31 AM Re: Sum in a txt file [Re: sygui]
sygui Offline
OL Expert

Registered: 11/02/10
Posts: 170
I get this error:

W3602 : Error 0 on line 12, column 1: Microsoft VBScript runtime error: Type mismatch: 'CLng'

Top
#57933 - 04/02/21 09:35 AM Re: Sum in a txt file [Re: sygui]
Jean-Cédric Offline
OL Expert

Registered: 10/03/16
Posts: 681
Loc: Québec, Canada
Const ForReading = 1
Const ForAppend = 8

mySum = 0

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(Watch.GetJobFileName, ForReading)

Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
if(left(strLine,3) = "32B") then
mySum = mySum + CLng(mid(strLine,5))
End If

Loop



objFile.Close

Set objFile = objFSO.OpenTextFile(Watch.GetJobFileName, ForAppend)
objFile.Write ":99N:" & mySum
objFile.Close
_________________________
♪♫♪♫
99 frigging bugs in my code
99 frigging bugs
Take one down
Code around
127 frigging bugs in my code
♪♫♪♫

Top
#57934 - 04/02/21 09:38 AM Re: Sum in a txt file [Re: sygui]
sygui Offline
OL Expert

Registered: 11/02/10
Posts: 170
Cedric, last thing it gives me 170 instead of 169.65

Top
#57935 - 04/02/21 09:44 AM Re: Sum in a txt file [Re: sygui]
Jean-Cédric Offline
OL Expert

Registered: 10/03/16
Posts: 681
Loc: Québec, Canada
Const ForReading = 1
Const ForAppend = 8

mySum = 0

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(Watch.GetJobFileName, ForReading)

Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
if(left(strLine,3) = "32B") then
mySum = mySum + CCur(mid(strLine,5))
End If

Loop



objFile.Close

Set objFile = objFSO.OpenTextFile(Watch.GetJobFileName, ForAppend)
objFile.Write ":99N:" & mySum
objFile.Close
_________________________
♪♫♪♫
99 frigging bugs in my code
99 frigging bugs
Take one down
Code around
127 frigging bugs in my code
♪♫♪♫

Top
#57936 - 04/02/21 10:08 AM Re: Sum in a txt file [Re: sygui]
sygui Offline
OL Expert

Registered: 11/02/10
Posts: 170
wow thks

Top