现在我的脚本如下:
Dim mon
Set mon=ScreenItems("list1")
Dim c
Set c=HMIRuntime.Tags("tag1")
c.Write mon.List(0)
Dim fso,File
Const ForWriting = 2
Set fso = CreateObject("Scripting.FileSystemObject")
Set FilE = fso.OpenTextFile("g:\1.txt", ForWriting, True)
File.WriteLine c.read
File.Close
脚本意思是读取list1上的第1个元素,并把值写到tag1中,同时将tag1写入1.txt中,现在想实现的是
从第1行开始,循环读取list1中的元素,每读取1个,就写入1.txt中一次,第二次从第二行开始写,一直到list1元素读完,最后的结果就是元素全部写入到了1.txt中,每个元素占1行。应该怎么修改啊?
Dim mon
Set mon=ScreenItems("list1")
Dim c
Set c=HMIRuntime.Tags("tag1")
Dim i
For i=LBound(mon.List) to UBound(mon.List)
c.Write mon.List(i)
Dim fso,File
Const ForWriting = 2
Set fso = CreateObject("Scripting.FileSystemObject")
Set FilE = fso.OpenTextFile("g:\1.txt", ForWriting, True)
File.WriteLine c.read
File.Close
Next
把文本关闭放到最后
Dim mon
Set mon=ScreenItems("list1")
Dim c
Set c=HMIRuntime.Tags("tag1")
Dim i
For i=LBound(mon.List) to UBound(mon.List)
c.Write mon.List(i)
Dim fso,File
Const ForWriting = 2
Set fso = CreateObject("Scripting.FileSystemObject")
Set FilE = fso.OpenTextFile("g:\1.txt", ForWriting, True)
File.WriteLine c.read
Next
File.Close