Vbscript 使用VBS编辑my.txt文档

Vbscript 使用VBS编辑my.txt文档,vbscript,Vbscript,在VBScript中,我想用新数据更新文本文件,并将其显示在消息框中 以下是我到目前为止的情况;我做错了什么 Option Explicit Dim oFso, Michael, John, Valery, Susane, Katterina Dim oStream, oFolder, f, myArrayList Const ForAppending = 8 Const ForReading = 1, ForWriting = 2 Set myArrayList = CreateObje

在VBScript中,我想用新数据更新文本文件,并将其显示在消息框中

以下是我到目前为止的情况;我做错了什么

Option Explicit 
Dim oFso, Michael, John, Valery, Susane, Katterina
Dim oStream, oFolder, f, myArrayList

Const ForAppending = 8
Const ForReading = 1, ForWriting = 2

Set myArrayList = CreateObject("System.Collections.ArrayList")  
    myArrayList.Add "Misko, Janko, Vierka,"

'create '
Call WriteLineToFile

Function WriteLineToFile
    Set oFso = CreateObject("Scripting.FileSystemObject") 
    Set f = oFso.CreateTextFile("D:\TestFile1.txt", 2, True)

    f.WriteLine "Misko, Janko, Vierka,"

    MsgBox "Subor C:\TestFile.txt bol " & "vytvoreny."

    f.Close

    Set f = Nothing
    Set oFso = Nothing

    MsgBox "Uspesne vytvoreny " & TestFile2.txt & "."   
End Function
SO、f、sPath、sPath2、i、sTemp‘deklaracia’的尺寸 Dim ARR字符串

Const ForReading = 1, ForWriting = 2
sPath=“D:\TestFile1.txt”'cesta ku datam'
sPath2=“D:\TestFile2.txt”

arrString=Array(“Marek”、“Tomas”)“pole alebo polia”
重拨字符串(2)
arrString(0)=“Misko”
arrString(1)=“Janko”
arrString(2)=“Vierka”

对于i=0到uBond(arrString)'ide po上限'
如果i=UBound(arrString),则
sTemp=sTemp+ARRSTING(i)'odstrani ciarku na konci'
其他的
sTemp=sTemp+arrString(i)+“
如果结束
下一个
MsgBox sTemp

Call WriteLineToFile (sPath, sTemp)         'zavola sub routine'
Sub WriteLineToFile (sFilePath, sText)      
    Set oFso = CreateObject("Scripting.FileSystemObject") 
    Set f = oFso.CreateTextFile(sFilePath, 2, True)
    'For i = 0 To UBound(arrString) - 1         'nepotrebne'
        f.WriteLine sText
    'Next
        MsgBox "Subor " & sFilePath & " vytvoreny."
ReDim字符串(4)
arrString(3)=“Zuzka”
arrString(4)=“Katka”

i=0到UBound(arrString)的

如果i=UBound(arrString),则
sTemp=sTemp+ARRSING(一)
其他的
sTemp=sTemp+arrString(i)+“
如果
下一个 MsgBox sTemp

Call WriteLineToFile (sPath, sTemp)         'zavola sub routine'
Sub WriteLineToFile (sFilePath, sText)      
    Set oFso = CreateObject("Scripting.FileSystemObject") 
    Set f = oFso.CreateTextFile(sFilePath, 2, True)
    'For i = 0 To UBound(arrString) - 1         'nepotrebne'
        f.WriteLine sText
    'Next
        MsgBox "Subor " & sFilePath & " vytvoreny."
调用WriteLineToFile(sPath2,sTemp)

f.Close
设置f=无
一组SO=零

End Sub

您是否收到错误?MsgBox“Uspesne vytvoreny”&TestFile2.txt&“行应该做什么?更新文本文件?您应该使用而不是CreateTextFile。
Sub WriteLineToFile (sFilePath, sText)      
    Set oFso = CreateObject("Scripting.FileSystemObject") 
    Set f = oFso.CreateTextFile(sFilePath, 2, True)
    'For i = 0 To UBound(arrString) - 1         'nepotrebne'
        f.WriteLine sText
    'Next
        MsgBox "Subor " & sFilePath & " vytvoreny."