Writing into the text file using vbs script.

Home Forums Scripting Windows Script Host Writing into the text file using vbs script.

This topic contains 2 replies, has 2 voices, and was last updated by Avatar igor7 9 years, 4 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • Avatar
    igor7
    Member
    #148905

    Hi everybody!!
    I trying automate some task… I need to create template for vCard File (phone contacts) that will contain ~ 700 contacts in Hebrew language. I created vbs script (based on some example I’ve found in Internet) that can add appropriate information to a text file:

    Option Explicit
    Dim objFSO, objFolder, objShell, objTextFile, objFile
    Dim strDirectory, strFile, strText, strText1, strText2, strText3, strText4, strText5
    strDirectory = “C:UsersIgorDesktopScript”
    strFile = “Text.txt”
    strText = “BEGIN:VCARD”
    strText1 = “VERSION:2.1”
    strText2 = “N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:”
    strText3 = “FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:”
    strText4 = “TEL:”
    strText5 = “END:VCARD”

    Set objFSO = CreateObject(“Scripting.FileSystemObject”)

    If objFSO.FolderExists(strDirectory) Then
    Set objFolder = objFSO.GetFolder(strDirectory)
    Else
    Set objFolder = objFSO.CreateFolder(strDirectory)
    WScript.Echo “Just created ” & strDirectory
    End If
    If objFSO.FileExists(strDirectory & strFile) Then
    Set objFolder = objFSO.GetFolder(strDirectory)
    Else
    Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
    Wscript.Echo “Just created ” & strDirectory & strFile
    End If
    set objFile = nothing
    set objFolder = nothing

    Const ForAppending = 8
    Set objTextFile = objFSO.OpenTextFile _
    (strDirectory & strFile, ForAppending, True)

    objTextFile.WriteLine(strText)
    objTextFile.WriteLine(strText1)
    objTextFile.WriteLine(strText2)
    objTextFile.WriteLine(strText3)
    objTextFile.WriteLine(strText4)
    objTextFile.WriteLine(strText5)

    objTextFile.Close
    WScript.Quit
    [/CODE]

    The output looks like:

    [CODE]
    BEGIN:VCARD
    VERSION:2.1
    N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:
    FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:
    TEL:
    END:VCARD
    BEGIN:VCARD
    VERSION:2.1
    N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:
    FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:
    TEL:
    END:VCARD
    [/CODE]

    But problem is, if I need add 700 contacts, I must click on script file 700 times…
    How I can add counter checker or something similar into this script? I mean one click on the script add 700 times same information into the text file.
    Any help is much appreciated![CODE]
    Option Explicit
    Dim objFSO, objFolder, objShell, objTextFile, objFile
    Dim strDirectory, strFile, strText, strText1, strText2, strText3, strText4, strText5
    strDirectory = “C:UsersIgorDesktopScript”
    strFile = “Text.txt”
    strText = “BEGIN:VCARD”
    strText1 = “VERSION:2.1”
    strText2 = “N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:”
    strText3 = “FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:”
    strText4 = “TEL:”
    strText5 = “END:VCARD”

    Set objFSO = CreateObject(“Scripting.FileSystemObject”)

    If objFSO.FolderExists(strDirectory) Then
    Set objFolder = objFSO.GetFolder(strDirectory)
    Else
    Set objFolder = objFSO.CreateFolder(strDirectory)
    WScript.Echo “Just created ” & strDirectory
    End If
    If objFSO.FileExists(strDirectory & strFile) Then
    Set objFolder = objFSO.GetFolder(strDirectory)
    Else
    Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
    Wscript.Echo “Just created ” & strDirectory & strFile
    End If
    set objFile = nothing
    set objFolder = nothing

    Const ForAppending = 8
    Set objTextFile = objFSO.OpenTextFile _
    (strDirectory & strFile, ForAppending, True)

    objTextFile.WriteLine(strText)
    objTextFile.WriteLine(strText1)
    objTextFile.WriteLine(strText2)
    objTextFile.WriteLine(strText3)
    objTextFile.WriteLine(strText4)
    objTextFile.WriteLine(strText5)

    objTextFile.Close
    WScript.Quit
    [/CODE]

    The output looks like:

    BEGIN:VCARD
    VERSION:2.1
    N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:
    FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:
    TEL:
    END:VCARD
    BEGIN:VCARD
    VERSION:2.1
    N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:
    FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:
    TEL:
    END:VCARD
    [/CODE]

    But problem is, if I need add 700 contacts, I must click on script file 700 times…
    How I can add counter checker or something similar into this script? I mean one click on the script add 700 times same information into the text file.
    Any help is much appreciated![CODE]
    BEGIN:VCARD
    VERSION:2.1
    N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:
    FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:
    TEL:
    END:VCARD
    BEGIN:VCARD
    VERSION:2.1
    N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:
    FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:
    TEL:
    END:VCARD
    [/CODE]

    But problem is, if I need add 700 contacts, I must click on script file 700 times…
    How I can add counter checker or something similar into this script? I mean one click on the script add 700 times same information into the text file.
    Any help is much appreciated!

    Rems
    Rems
    Moderator
    #227710

    Re: Writing into the text file using vbs script.

    igor7;203564 wrote:
    ….I must click on script file 700 times…
    How I can add counter checker or something similar into this script? I mean one click on the script add 700 times same information into the text file.

    x = 700

    for iCnt = 1 to x
    objTextFile.WriteLine(strText)
    objTextFile.WriteLine(strText1)
    objTextFile.WriteLine(strText2)
    objTextFile.WriteLine(strText3)
    objTextFile.WriteLine(strText4)
    objTextFile.WriteLine(strText5)
    next[/CODE][CODE]x = 700

    for iCnt = 1 to x
    objTextFile.WriteLine(strText)
    objTextFile.WriteLine(strText1)
    objTextFile.WriteLine(strText2)
    objTextFile.WriteLine(strText3)
    objTextFile.WriteLine(strText4)
    objTextFile.WriteLine(strText5)
    next[/CODE]

    Avatar
    igor7
    Member
    #295060

    Re: Writing into the text file using vbs script.

    Rems;203582 wrote:
    x = 700

    for iCnt = 1 to x[/CODE] [/QUOTE]
    Thanks, Rems,- now my life match easier!!![CODE]x = 700

    for iCnt = 1 to x[/CODE]

    Thanks, Rems,- now my life match easier!!!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.