Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Error in vbs script  (Read 2835 times)

0 Members and 1 Guest are viewing this topic.

progmer

    Topic Starter


    Rookie

    Error in vbs script
    « on: May 25, 2010, 09:27:52 PM »
    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?

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: Error in vbs script
    « Reply #1 on: May 25, 2010, 09:39:17 PM »

    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.
    I was trying to dereference Null Pointers before it was cool.