菜鸟:
我在电脑上有一个txt的文件,在WINCC中通过VBS 来读取,但是发现程序走到打开文件,读取的那一步,走不下去了,大家帮我看一下,我错在什么地方。 多谢!具体的程序如下:
Sub OnClick(Byval Item)
Dim fso
Dim txtfile
Dim szContent
HMIRuntime.Tags("Wri_00").Write 0
Set fso = CreateObject("s cripting.FileSystemObject")
HMIRuntime.Tags("Wri_00").Write 1
Set txtfile = fso.OpenTextFile("C:My Work StationWinCC Test.txt",ForReading)
HMIRuntime.Tags("Wri_00").Write 2
szContent = txtfile.ReadAll
HMIRuntime.Tags("Wri_00").Write 3
HMIRuntime.Tags("Rea").Write txtfile.ReadLine
HMIRuntime.Tags("Wri_00").Write 4
txtfile.close
End Sub
我的程序只能走到Set txtfile = fso.OpenTextFile("C:My Work StationWinCC Test.txt",ForReading) 这个地方,但是这个地方的语句并没有被执行。
是不是这个语句有问题?那么问题又是什么?
多谢大家了!
奇侠:
wincc中怎样用vbs脚本创建txt文档?并写入一句话? - 已解决问题 -自动化系统- 找答案 - 支持中心 - 西门子(中国)有限公司工业业务领域 (SLC Industry)
http://www.ad.siemens.com.cn/service/answer/solution.aspx?Q_ID=52020&cid=1027看这个
菜鸟:
我这个不是创建TXT 文件,是TXT文件已经存在,用VBS,来读取TXT文件中的内容。我用C脚本已经做出来了,但是用VBS走到我说的那一步,就走不下去了。 我看了半天也没看出来有什么地方不对,您发的链接我看了,是往TXT中写内容的。
菜鸟:
我想我已经找到问题的答案了,多谢了。我没有定义ForReading 作为一个常量,且值为真。
Dim fso,file,file1,filename,filename1,dev,rtdata,a,b
Dim i
filename="D:\yt090305bak\data\dev.txt"
filename1="D:\yt090305bak\data\rtdata.txt"
Const ForReading=1
Set fso=CreateObject("s cripting.FileSystemObject")
Set file=fso.opentextfile(filename,ForReading)
Set file1=fso.opentextfile(filename1,ForReading)
Do Until file.AtEndOfLine=-1
dev=file.ReadLine
rtdata=file1.ReadLine
i=i+1
Select Case i
case 1
b= Split(rtdata, ",")
HMIRuntime.Tags("时间").Write b(1)
Case 2
a = Split(dev, ",")
b = Split(rtdata, ",")
HMIRuntime.Tags("当前值2").Write b(1)
HMIRuntime.Tags("测点编号2").Write a(1)
HMIRuntime.Tags("传感器安装地点2").Write a(2)
HMIRuntime.Tags("传感器名称2").Write a(3)
HMIRuntime.Tags("传感器类型编码2").Write a(4)
HMIRuntime.Tags("单位2").Write a(5)
HMIRuntime.Tags("量程上限2").Write a(7)
HMIRuntime.Tags("解警值2").Write a(8)
HMIRuntime.Tags("报警值2").Write a(9)
HMIRuntime.Tags("断电值2").Write a(10)
HMIRuntime.Tags("复电值2").Write a(11)
If a(11)=1 Then
HMIRuntime.Tags("模拟量_2").Write 1
HMIRuntime.Tags("控制量_2").Write 0
Else
HMIRuntime.Tags("模拟量_2").Write 0
HMIRuntime.Tags("控制量_2").Write 1
End if
Case 3
a = Split(dev, ",")
b = Split(rtdata, ",")
HMIRuntime.Tags("瓦斯当前值3").Write b(1)
HMIRuntime.Tags("测点编号3").Write a(1)
HMIRuntime.Tags("传感器安装地点3").Write a(2)
HMIRuntime.Tags("传感器名称3").Write a(3)
HMIRuntime.Tags("传感器类型编码3").Write a(4)
HMIRuntime.Tags("单位3").Write a(5)
HMIRuntime.Tags("量程上限3").Write a(7)
HMIRuntime.Tags("解警值3").Write a(8)
HMIRuntime.Tags("报警值3").Write a(9)
HMIRuntime.Tags("断电值3").Write a(10)
HMIRuntime.Tags("复电值3").Write a(11)
If a(11)=1 Then
HMIRuntime.Tags("模拟量_3").Write 1
HMIRuntime.Tags("控制量_3").Write 0
Else
HMIRuntime.Tags("模拟量_3").Write 0
HMIRuntime.Tags("控制量_3").Write 1
End if
End Select
Loop
file.Close