Announcement

Collapse
No announcement yet.

Writing into the text file using vbs script.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Writing into the text file using vbs script.

    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:

    Code:
     
    Option Explicit
    Dim objFSO, objFolder, objShell, objTextFile, objFile
    Dim strDirectory, strFile, strText, strText1, strText2, strText3, strText4, strText5
    strDirectory = "C:\Users\Igor\Desktop\Script"
    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
    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
    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!

  • #2
    Re: Writing into the text file using vbs script.

    Originally posted by igor7 View Post
    ....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.

    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

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Writing into the text file using vbs script.

      Originally posted by Rems View Post
      Code:
      x = 700
       
      for iCnt = 1 to x
      Thanks, Rems,- now my life match easier!!!

      Comment

      Working...
      X