Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do not write line by line to file instead dumps data at end, any idea

Status
Not open for further replies.

bolobaboo

MIS
Aug 4, 2008
120
US
Hi
I have following code is part of main script, But problem is I am expecting it to write to file ( tslog)line by line as it goes thru loop, It does not happen that way code dumps all lines once it exit loop. Any idea ?
.
.
Do Until tsList.AtEndOfStream
strVOLSER = Trim( tsList.ReadLine )
If dicVOLSERs.Exists( strVOLSER ) Then
intRowToUpdate = dicVOLSERs( strVOLSER )
tsLog.WriteLine Join( Array( Now, "|" & strVOLSER & "| => " & intRowToUpdate ), " " )
oExcel.Cells( intRowToUpdate, 5 ) = aChanges( 0 )
oExcel.Cells( intRowToUpdate, 4 ) = aChanges( 1 )
Else
tsLog.WriteLine Join( Array( Now, "|" & strVOLSER & "| => Surprise, surprise" ), " " )
End If
Loop
.
.
.
 
It isn't clear what problem you're seeing.

Do you know the FSO output is buffered and not flushed to disk until buffers fill or you close the textstream, right?
 
Here is entire code ..

Option Explicit
Const ForAppending = 8
Dim oFS : Set oFS = CreateObject( "Scripting.FileSystemObject" )
Dim tsLog : Set tsLog = oFS.OpenTextFile( ".\update.log", ForAppending, True )
Dim dicVOLSERs : Set dicVOLSERs = CreateObject( "Scripting.Dictionary" )
Dim oExcel : Set oExcel = CreateObject("Excel.Application")
Dim oWBook : Set oWBook = oExcel.Workbooks.Open( oFS.GetAbsolutePathName( ".\totaltapes.xls") )
Dim tsList : Set tsList = oFS.OpenTextFile( ".\list.txt" )
Dim intRow : intRow = 2
Dim strVOLSER, intRowToUpdate,newdate,newlocation,iResponce,progr
Dim aChanges : aChanges = getChanges()
progr = "progressbar.txt"
If IsEmpty( aChanges ) Then
tsLog.WriteLine Join( Array( Now, "Aborted" ), " " )
If ofs.FileExists (progr) Then
ofs.DeleteFile progr, True
End If
tsLog.Close
WScript.Quit 1
End If
iResponce = MsgBox("Do You want to continue updating sheet ???", vbYesNo, "Updating sheet with date and location.")
If iResponce = vbYes Then ' They Clicked YES!
Else
tsLog.Close
If ofs.FileExists (progr) Then
ofs.DeleteFile progr, True
End If
WScript.Quit 1
End If

Do Until oExcel.Cells(intRow, 1).Value = ""
dicVOLSERs( oExcel.Cells(intRow, 2).Value ) = intRow
intRow = intRow + 1
Loop

Do Until tsList.AtEndOfStream
strVOLSER = Trim( tsList.ReadLine )
If dicVOLSERs.Exists( strVOLSER ) Then
intRowToUpdate = dicVOLSERs( strVOLSER )
tsLog.WriteLine Join( Array( Now, "|" & strVOLSER & "| => " & intRowToUpdate ), " " )
oExcel.Cells( intRowToUpdate, 5 ) = aChanges( 0 )
oExcel.Cells( intRowToUpdate, 4 ) = aChanges( 1 )
Else
tsLog.WriteLine Join( Array( Now, "|" & strVOLSER & "| => Surprise, surprise" ), " " )
End If
Loop
tsList.Close

oWBook.Save
oExcel.Application.Quit
If ofs.FileExists (progr) Then
ofs.DeleteFile progr, True
End If
wscript.echo "Process Completed !!"
WScript.Quit 0

Function getChanges()
Do
newdate = inputbox ("New date for these tapes", "Enter New date ")
If newdate = "" Then
Wscript.Echo "You must enter a Date."
Else
Exit Do
End If
Loop

Do
newlocation = inputbox ("New location for these tapes", "Enter New location for these Tapes ")
If newlocation = "" Then
Wscript.Echo "You must enter Newlocation for Tapes."
Else
Exit Do
End If
Loop
getChanges = Array( newdate, newlocation )
End Function
 
dilettante addressed the behavior you are seeing. Were you just curioius why this happened? Or, is this causing a problem for you... ??
 
>It does not happen that way code dumps all lines once it exit loop. Any idea ?
How do you know? The writeline is "immediate" or synchronous.

In any case, add
[tt] tsLog.Close[/tt]
after tsList.Close.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top