Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


read fixed length text file and add totals

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,36952
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> read fixed length text file and add totals
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 read fixed length text file and add totals - 8/13/2006 11:59:59 PM   
  bigfatgreedykat

 

Posts: 34
Score: 0
Joined: 2/2/2006
Status: offline
Hello all

I have a fixed length text file. I can use WScript echo to display results but would like to add all numbers display.

Is this possible?

Please advise.

Look forward to your replies and thans in advance for all your help.

regards

BFGK
 
 
Post #: 1
 
 RE: read fixed length text file and add totals - 8/14/2006 1:06:31 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: online
I don't understand what you are asking with this:

"...but would like to add all numbers display. "

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to bigfatgreedykat)
 
 
Post #: 2
 
 RE: read fixed length text file and add totals - 8/14/2006 5:57:39 PM   
  bigfatgreedykat

 

Posts: 34
Score: 0
Joined: 2/2/2006
Status: offline

Set
objFSO = createObject("Scripting.FileSystemObject")

Set
objFile = objFSO.OpenTextFile("C:\MBR\718.txt", 2021)

Do
Until objFile.AtEndOfStream
objFile.SkipLine
objFile.Skip(
34)
strCharacters = objFile.Read(
3233)
Wscript.Echo strCharacters

Hello the above displays all numbers but i would like a total. WScript displays 15 then 20 then 15 then 25 but i would like to see total 75.

Please advise

Look forward to your reply

thanks

BFGK

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: read fixed length text file and add totals - 8/14/2006 11:16:36 PM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: online
How are the numbers seperated? Each number on a different line?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to bigfatgreedykat)
 
 
Post #: 4
 
 RE: read fixed length text file and add totals - 8/14/2006 11:19:17 PM   
  bigfatgreedykat

 

Posts: 34
Score: 0
Joined: 2/2/2006
Status: offline
Hello

Numbers are displayed individually in each pop up box but i would just like to read total

thanks

BFGK

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: read fixed length text file and add totals - 8/14/2006 11:24:44 PM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: online
To help you I need to know in the file that you are reading from, how are the numbers seperated?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to bigfatgreedykat)
 
 
Post #: 6
 
 RE: read fixed length text file and add totals - 8/14/2006 11:35:36 PM   
  bigfatgreedykat

 

Posts: 34
Score: 0
Joined: 2/2/2006
Status: offline
010718000020060731000000000000000000000000000000000000000000000000000000000000000000000000
030718000120060731000000000071800015001320005038289000477001000000000000000000000000000100
030718000120060731000000000071800015001333006080584000468001000000000000000000000000000100
030718000120060731000000000071800013501716014093396000578401000000000000000000000000000100
030718000120060731000000000071800029000944027048960000224401000000000000000000000000000200
030718000120060731000000000071800025001414028049523000533501000000000000000000000000000100
030718000120060731000000000071800025001236097031189000427001000000000000000000000000000100


(in reply to ebgreen)
 
 
Post #: 7
 
 RE: read fixed length text file and add totals - 8/14/2006 11:49:27 PM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: online
I still don't see how you could take one of the lines that you have posted, read 3233 characters from it and have it display a number like 15 or 20. Oh well, either way, try replacing this line:

Wscript.Echo strCharacters

with this:

nTotal = nTotal + CInt(strCharacters)

Then after you have looped through the entire file stick in this line:

WScript.Echo nTotal


_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to bigfatgreedykat)
 
 
Post #: 8
 
 RE: read fixed length text file and add totals - 8/15/2006 12:40:27 AM   
  bigfatgreedykat

 

Posts: 34
Score: 0
Joined: 2/2/2006
Status: offline
Hello, thats works great but now i get an error:

Input past end of file

Any ideas - i'm searching net for an answer!!!

thanks again

BFGK

(in reply to ebgreen)
 
 
Post #: 9
 
 RE: read fixed length text file and add totals - 8/15/2006 1:32:35 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: online
Most likely you are trying to read past the end of the file. The best bet for help is to post a sample of the file you are parsing, the code that you are using, what you are trying to accomplish, and the error (with line number) that you are getting. Otherwise we are just shooting in the dark trying to help you.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to bigfatgreedykat)
 
 
Post #: 10
 
 RE: read fixed length text file and add totals - 8/17/2006 12:17:19 AM   
  bigfatgreedykat

 

Posts: 34
Score: 0
Joined: 2/2/2006
Status: offline
Set objFSO = createObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("d:\MBR\718.txt", 1)
Do until objFile.AtEndOfStream
objFile.SkipLine
objFile.Skip(34)
strCharacters = objFile.Read(2)
nTotal = nTotal + CInt(strCharacters)
Set objFSO = Nothing
WScript.Echo nTotal
Loop
objFile.Close




Thanks in advance

BFGK

(in reply to ebgreen)
 
 
Post #: 11
 
 RE: read fixed length text file and add totals - 8/17/2006 12:23:05 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: online
I think your best bet would be to do this without using Skips. Try this:

Set objFSO = createObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("d:\MBR\718.txt", 1)
arrLines = Split(objFile.ReadAll, vbCrLf)
For Each strLine In arrLines
    nTotal = nTotal + Mid(strLine, 34, 2)
Loop
Set objFSO = Nothing
WScript.Echo nTotal
objFile.Close

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to bigfatgreedykat)
 
 
Post #: 12
 
 RE: read fixed length text file and add totals - 8/17/2006 12:39:05 AM   
  bigfatgreedykat

 

Posts: 34
Score: 0
Joined: 2/2/2006
Status: offline
hello text file can numerous size with many lines downwards. only the position of the numbers i require are static

(in reply to ebgreen)
 
 
Post #: 13
 
 RE: read fixed length text file and add totals - 8/17/2006 12:42:39 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: online
Did you try the code that I posted? It will work the same whether the file is 3 lines or 3,000,000 lines. 

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to bigfatgreedykat)
 
 
Post #: 14
 
 RE: read fixed length text file and add totals - 8/17/2006 12:55:08 AM   
  bigfatgreedykat

 

Posts: 34
Score: 0
Joined: 2/2/2006
Status: offline
error
line:20
error: 'loop' without 'do'
code: 800A040E

(in reply to ebgreen)
 
 
Post #: 15
 
 RE: read fixed length text file and add totals - 8/17/2006 1:31:05 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: online
Oops...that's what I get for trying to be lazy and alter your code instead of doing it myself. Change the Loop to Next.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to bigfatgreedykat)
 
 
Post #: 16
 
 RE: read fixed length text file and add totals - 8/22/2006 2:11:55 AM   
  bigfatgreedykat

 

Posts: 34
Score: 0
Joined: 2/2/2006
Status: offline
Hello

I've been playing and testing but output still doesn't provide total

It now displays: 30 zero's

Please advise, thanks

BGFK


(in reply to ebgreen)
 
 
Post #: 17
 
 RE: read fixed length text file and add totals - 8/22/2006 2:37:35 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: online
Ok, I stopped trying to do it in my head and played with it some. This looks like it works to me:

Set objFSO = createObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("d:\MBR\718.txt", 1)
arrLines = Split(objFile.ReadAll, vbCrLf)
For Each strLine In arrLines
   strSegment = Mid(strLine, 35, 2)
   If Not strSegment = "" Then
       nThisOne = (CInt(Mid(strSegment, 1, 1)) * 10) + (CInt(Mid(strSegment, 2, 1)))
       nTotal = nTotal + nThisOne
   End If
Next
Set objFSO = Nothing
WScript.Echo nTotal
objFile.Close

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to bigfatgreedykat)
 
 
Post #: 18
 
 RE: read fixed length text file and add totals - 8/22/2006 3:06:19 AM   
  bigfatgreedykat

 

Posts: 34
Score: 0
Joined: 2/2/2006
Status: offline
Wow, thats great.

I seriously doubt if i would have ever come up with that as a solution.

Is it possible to place "nTotal" in subject line of a email script. Would that work?

Look forward to your reply

thanks again

BFGK

(in reply to ebgreen)
 
 
Post #: 19
 
 RE: read fixed length text file and add totals - 8/22/2006 3:10:14 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: online
It would be entirely possible. Search this site and you will find lots of examples of sending emails via script.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to bigfatgreedykat)
 
 
Post #: 20
 
 
Page:   [1] 2   next >   >>
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> read fixed length text file and add totals Page: [1] 2   next >   >>
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts