0% found this document useful (0 votes)
98 views

VBS ReadFile

This VBScript subroutine reads data from a text file containing tag names and values separated by semicolons, and writes the values to those tags in the runtime. It gets the filename from a tag, checks that the file exists, then opens it and reads each line, splitting it into the tag name and value. It outputs the name and value to the trace, sets the tag object, and writes the value. It loops until the end of the file, then closes the file.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views

VBS ReadFile

This VBScript subroutine reads data from a text file containing tag names and values separated by semicolons, and writes the values to those tags in the runtime. It gets the filename from a tag, checks that the file exists, then opens it and reads each line, splitting it into the tag name and value. It outputs the name and value to the trace, sets the tag object, and writes the value. It loops until the end of the file, then closes the file.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Sub OnClick(Byval Item)

Dim tagName, tagValue, tagFilename


Dim strFilename, strLine, arrItems
Dim fso, objFile, objTag
Set tagFilename = HMIRuntime.Tags("Filename")
Set fso = CreateObject("Scripting.FileSystemObject")
strFilename = tagFilename.Read
If fso.FileExists(strFilename) Then
'for Control
HMIRuntime.Trace("VB-Script: read file: " & strFilename & vbCrLf
)
Set objFile = fso.OpenTextFile(strFilename,1)
Do
strLine = objFile.ReadLine
arrItems = Split(strLine, ";", -1, 1)
tagName = CStr(arrItems(0))
tagValue = CDbl(arrItems(1))
'for Control
HMIRuntime.Trace(tagName & " Value: " & TagValue & vbC
rLf )
Set objTag = HMIRuntime.Tags(Tagname)
objTag.Value = tagValue
objTag.Write
Loop Until objFile.AtEndOfStream
Else
HMIRuntime.Trace("File: " & strFilename &" not found!" & vbCrLf)
End If
objFile.Close
End Sub

You might also like