1.

Solve : Error in vbs script?

Answer»

Code: [Select]Const ForAppending = 8
On error resume next
Set fso = CreateObject("Scripting.FileSystemObject")
Set IsoFile = fso.CreateTextFile("C:\Documents and Settings\User\Desktop\Testing.vbs", False)
Set IsoFile = fso.OpenTextFile("C:\Documents and Settings\User\Desktop\Testing.vbs", ForAppending)
IsoFile.WriteLine "count = 0"
IsoFile.WriteLine "do"
IsoFile.WriteLine "x=msgbox("Hello World!",,"Hello!")"
IsoFile.WriteLine "count = count +1"
IsoFile.WriteLine "Loop until count = 10"

There is a problem because the vbs script cannot create a data that has the symbol: "" or ()
When it continue writing data in an existed file. The FIRST LINE seems to not be available. ( The "Count = 0" will not be writen)
Any way to SOLVE this problem?
Code: [Select]Const ForAppending = 8
On error resume next
Set fso = CreateObject("Scripting.FileSystemObject")
Set IsoFile = fso.CreateTextFile("C:\Documents and Settings\User\Desktop\Testing.vbs", False)
Set IsoFile = fso.OpenTextFile("C:\Documents and Settings\User\Desktop\Testing.vbs", ForAppending)
IsoFile.WriteLine "count = 0"
IsoFile.WriteLine "do"
IsoFile.WriteLine "x=msgbox(""Hello World!"",,""Hello!"")"
IsoFile.WriteLine "count = count +1"
IsoFile.WriteLine "Loop until count = 10"

to insert quotes in a quoted string literal use TWO quotes.



Discussion

No Comment Found