回复:VBS 脚本读取TXT文件,请教

zhangli0

版主 西门子1847工业学习平台

  • 帖子

    17401
  • 精华

    65
  • 被关注

    918

论坛等级:至圣

注册时间:2003-06-06

钻石 钻石 如何晋级?

发布于 2014-01-10 15:21:20

5楼

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
活到老,学到老!为了生活学习吧!
评论
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC WinCC / Panel

共有32939条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

快扫描右侧二维码晒一晒吧!

再发帖或跟帖交流2条,就能晋升VIP啦!开启更多专属权限!

  • 分享

  • 只看
    楼主

top
X 图片
您收到0封站内信:
×
×
信息提示
很抱歉!您所访问的页面不存在,或网址发生了变化,请稍后再试。