Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - line space in log file

Reply
 
Old 07-25-2008   #1 (permalink)
systemtek


 
 

line space in log file

Hi all, having a few problems with the below script, its part of a
bigger script but this is the part we having problems with.

It creates the log file with the results, but when you run it agin it
overwrites the previos results, is there a way to have the results on
each line in the log ?

Set objTxtFSO = CreateObject("Scripting.FileSystemObject")
strPath = "c:\file.log"
Set ObjTxtFile = ObjTxtFSO.OpenTextFile (strPath, ForAppending,
False, TristateFalse)

objTxtFile.Write(strName & ",")
objTxtFile.Write(strServtag & ",")
objTxtFile.Write(strSiteName & ",")
objTxtFile.Write(strLaptop & ",")
objTxtFile.Writeline(strUser)
objTxtFile.Close

My System SpecsSystem Spec
Old 07-25-2008   #2 (permalink)
ekkehard.horner


 
 

Re: line space in log file

systemtek schrieb:
Quote:

> Hi all, having a few problems with the below script, its part of a
> bigger script but this is the part we having problems with.
>
> It creates the log file with the results, but when you run it agin it
> overwrites the previos results, is there a way to have the results on
> each line in the log ?
>
> Set objTxtFSO = CreateObject("Scripting.FileSystemObject")
> strPath = "c:\file.log"
> Set ObjTxtFile = ObjTxtFSO.OpenTextFile (strPath, ForAppending,
> False, TristateFalse)
>
> objTxtFile.Write(strName & ",")
> objTxtFile.Write(strServtag & ",")
> objTxtFile.Write(strSiteName & ",")
> objTxtFile.Write(strLaptop & ",")
> objTxtFile.Writeline(strUser)
> objTxtFile.Close
Code like this (thou won't use () in the .Write(line) calls) works
for me reliably. Does "previous results" mean "last line" or "entire
file"? Do you use "On Error Resume Next" and/or "Option Explicit"?

In any case: I'd double check the definitions of "ForAppending"
and "TristateFalse"; test the script on a new file; test a simple
version of the writing: e.g. objTxtFile.Writeline "Geht doch!"; make
sure of the datatypes and contents of the str* variables.
My System SpecsSystem Spec
Old 07-25-2008   #3 (permalink)
Old Pedant


 
 

RE: line space in log file

> It creates the log file with the results, but when you run it agin it
Quote:

> overwrites the previos results
Quote:

> Set ObjTxtFile = ObjTxtFSO.OpenTextFile (strPath, ForAppending,
> False, TristateFalse)
ForAppending needs to be the value 8.

If you aren't assigning a value to that variable anywhere in your code, then
who knows what it is?

You can try just using 8, instead.
Set ObjTxtFile = ObjTxtFSO.OpenTextFile (strPath, 8 )
[The other two values default to False and TristateFalse, so you really
don't need to code them.]

Also, you can gain some efficiency (nanoseconds, likely, but still...) by
coding your writes all in a single line, thus:

Set objTxtFSO = CreateObject("Scripting.FileSystemObject")
strPath = "c:\file.log"
Set ObjTxtFile = ObjTxtFSO.OpenTextFile(strPath, 8 )
objTxtFile.WriteLine strName & "," & strServtag & "," & strSiteName & "," _
& strLaptop & "," strUser
objTxtFile.Close

Incidentally, you don't need parentheses with Write or WriteLine. In fact,
they are technically incorrect. And, again, will impose a few nanoseconds
performance penalty.




My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
No line space after issuing ping command on Vista SP1 Vista General
Read a line from a text file, without loading the entire file inmemory PowerShell
Re: What happeens when you try? Use the big white space under the Subject line and tell us all about it. Vista mail
reading a big file line by line to be "out of memory" safe PowerShell
"<SPACE> next page; <CR> next line; Q quit" not cleared in console PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46