Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VBScript runtime error: Input past end of file

773 views
Skip to first unread message

darren shelton

unread,
Sep 3, 2003, 9:31:46 PM9/3/03
to
I have an enterprise management application that writes events to a
proprietary event log. In their SDK they provide the sources to
convert their logs to CSV (I want them in a database so they are
easily searchable). The only problem with that is the time that when
events are written into the log, they do not have a date stamp, only a
timestamp (the log rolls over nightly). I am working on a VBScript to
add the dates into the CSV's such that they 'look' like a SQL server
DATETIME(). The filename of the CSV is the date the log was generated.

Here is an abbreviated line of hypothetical data:
10,D,D,12:23:42,Me,,No,,,,,SRVARL01,SYSTEM,,"October
29,No,,,NT,,,CAOP,WNT

What I need to do is make the data look like the following:
10,D,D,10/29/2000 12:23:42,Me,,No,,,,,SRV,SYSTEM,,"October
29,No,,,NT,,,CAOP,WNT

The date has been put in the fourth field right before the timestamp.
The date was pulled from the filename and a new CSV was written using
the following script:

--Begin Script
Option Explicit

' Constants '
Const ForReading = 1 'Read only attribute for OpenTextFile'
Const ForAppending = 8 'Append attribute for OpenTextFile'

' Variables '
Dim strFileName 'File Name w/o extension Passed to the Script'
Dim strFullFileName 'File Name w/ Extension Passed to the Script'
Dim strDateYear 'Get the year out of our date/filename'
Dim strDateDay 'Get the day out of our date/filename'
Dim strDateMonth 'Get the month out of our date/filename'
Dim strFileDate 'Actual Date from the filename'
Dim objFSOread 'FSO for reading the original CSV'
Dim objCSVorig 'Original CSV file object'
Dim objCSVnew 'New CSV with the merged date'
Dim objFSOwrite 'New FSO for the new CSV'

' Arrays '
Dim arrConLog 'Array for reading the original CSV'
Dim arrConLogNew(5) 'Array for writing the concatenated date/time'

'Pull the name of the file to use to get the date for each record in
the file'
'The full file name is used later on to open the text file for
reading and to'
'create the new file for the merged date/time.'
strFileName = Left(WScript.Arguments.Item(0), 8)
strFullFileName = WScript.ARguments.Item(0)

' Cut the date apart to get the year, month and day'
strDateYear = Left(strFileName, 4)
strDateDay = Right(strFileName, 2)
strDateMonth = Mid(strFileName, 5, 2)

'Concatenate the parts of the date to a format that is acceptable to
MS'
strFileDate = strDateMonth & "/" & strDateDay & "/" & strDateYear

'Check to make sure that the concatenated date is truly a date'
If IsDate(strFileDate) <> 0 Then
'WScript.Echo strFileDate'
Else
WScript.Echo "Your filename does not contain a valid date"
End If

'Open the original CSV and start reading records into the array
arrConLog()'
Set objFSOread = CreateObject("Scripting.FileSystemObject")
Set objCSVorig = objFSOread.OpenTextFile("d:\development\vb-script\" &
strFullFileName, ForReading, False)
'Create the new CSV'
Set objFSOwrite = CreateObject("Scripting.FileSystemObject")
Set objCSVnew = objFSOwrite.OpenTextFile("d:\development\vb-script\" &
strFileName & "-2.csv" , ForAppending, True)

Do While objCSVorig.AtEndOfStream <> True
If inStr(objCSVorig.Readline, ",") Then
arrConLog = split(objCSVorig.Readline, "," ,5)
arrConLogNew(0) = arrConLog(0)
arrconLogNew(1) = arrConLog(1)
arrConLogNew(2) = arrConLog(2)
arrConLogNew(3) = strFileDate & " " & arrConLog(3)
arrConLogNew(4) = arrConLog(4)
'Write the values into the new array and the new CSV'
objCSVnew.WriteLine join(arrConLogNew, ",")
Erase arrConLog
Erase arrConLogNew
Else
objCSVorig.Skipline
End If
Loop

'Close the open files'
objCSVorig.Close
objCSVnew.Close
--End Script


The problem i am having is my input file has approximately 100000
lines in it and the script is quitting halfway through the file. It
doesnt matter what size file i use, if it is 10 lines, or 50 lines or
2 lines.
The error being generated is the:

VBScript runtime error: Input past end of file.

I am quite new to VB (Transplanted from the *nix world) and am not
even sure if i am approaching this problem correctly from a VB
perspective. If anyone could shed some light on what is causing my
error, or suggest a better way to do it, I would be deeply
appreciative.

Thanks,

Darren

Michael Harris (MVP)

unread,
Sep 3, 2003, 10:40:36 PM9/3/03
to
I assume you really wan't to read *every* line, rather than every *other*
line...

...
Dim sLine
...
..
.
Do While objCSVorig.AtEndOfStream <> True
sLine = objCSVorig.Readline
If inStr(sLine , ",") Then
arrConLog = split(sLine , "," ,5)


arrConLogNew(0) = arrConLog(0)
arrconLogNew(1) = arrConLog(1)
arrConLogNew(2) = arrConLog(2)
arrConLogNew(3) = strFileDate & " " & arrConLog(3)
arrConLogNew(4) = arrConLog(4)
'Write the values into the new array and the new CSV'
objCSVnew.WriteLine join(arrConLogNew, ",")
Erase arrConLog
Erase arrConLogNew

End If
Loop
.
..
...

--
Michael Harris
Microsoft.MVP.Scripting

Windows 2000 Scripting Guide
Microsoft® Windows®2000 Scripting Guide
http://www.microsoft.com/technet/scriptcenter/scrguide/sagsas_overview.asp

System Administration Scripting Guide - samples scripts
http://www.microsoft.com/downloads/release.asp?ReleaseID=38942

WSH 5.6 documentation download
http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en

darren shelton

unread,
Sep 4, 2003, 2:31:26 AM9/4/03
to
"Michael Harris \(MVP\)" <mik...@mvps.org> wrote in message news:<Oq7h#2ocDH...@TK2MSFTNGP10.phx.gbl>...

> I assume you really wan't to read *every* line, rather than every *other*
> line...

You were absolutely correct, I wanted each line of my file worked on.
Your suggested remedy worked flawlessly.

I am curious though, why was the mechanism i used reading every other
line (I didnt check the data until you said so) and moving the
.ReadLine out of the If have the desired effect?

Thanks so much for your help and your speedy reply.


Darren

Joe Earnest

unread,
Sep 4, 2003, 6:55:40 AM9/4/03
to
Hi,

"darren shelton" <darren....@americredit.com> wrote in message
news:514ba58b.03090...@posting.google.com...


| "Michael Harris \(MVP\)" <mik...@mvps.org> wrote in message
news:<Oq7h#2ocDH...@TK2MSFTNGP10.phx.gbl>...
| > I assume you really wan't to read *every* line, rather than every
*other*
| > line...
|
| You were absolutely correct, I wanted each line of my file worked on.
| Your suggested remedy worked flawlessly.
|
| I am curious though, why was the mechanism i used reading every other
| line (I didnt check the data until you said so) and moving the
| .ReadLine out of the If have the desired effect?

Each time you use the ReadLine method, the script reads a line. Your
original code:

Do While objCSVorig.AtEndOfStream <> True
If inStr(objCSVorig.Readline, ",") Then
arrConLog = split(objCSVorig.Readline, "," ,5)

was reading one file line in the If operator line and a second in the Split
function line.

Michael's code:

Do While objCSVorig.AtEndOfStream <> True
sLine = objCSVorig.Readline
If inStr(sLine , ",") Then

only reads the line once, assigns it to a variable, and then operates on the
variable.

Joe Earnest

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.512 / Virus Database: 309 - Release Date: 08-19-03


darren shelton

unread,
Sep 4, 2003, 12:29:12 PM9/4/03
to
"Joe Earnest" <joeea...@qwest.net> wrote in message news:<eCWshItc...@TK2MSFTNGP12.phx.gbl>...

Thanks so much for your explanation. The problem was my
misunderstanding of the use of ReadLine.


Thanks Michael and Joe for all of your help,


Darren

0 new messages