Hello,
I am currently in the middle of a project and looking to read data from a .csv file on a server. I need to read this data and get it into the PLC so I can then compare the information for some necessary checks of validation. I have wrote a script already that can read the data, but I do not know how to save it to an array or structure and bring it into the PLC. Can any help point me in the right direction or provide any examples?
Here is my existing script:
'Declaration of local tags -
Dim fso, f, ts, Path, field, MyZf, i, j, k, HiField(2,6)
'Definition of local tags -
i=0
j=0
k=0
Path = "C:\Datalog1.csv"
'Error Routine -
On Error Resume Next
'Create object -
Set fso = CreateObject("Scripting.FileSystemObject")
If Err.Number <> 0 Then
ShowSystemAlarm "Error #" & CStr(Err.Number) & " " & Err.Description
Err.Clear
Exit Sub
End If
Set f = fspenTextFile(Path, 1, 0, -2)
If Err.Number <> 0 Then
ShowSystemAlarm "Error #" & CStr(Err.Number) & " " & Err.Description
Err.Clear
Exit Sub
End If
'Loop
Do While f.AtEndOfStream <> True
MyZf = f.ReadLine
field = Split(MyZf, ",")
For i=0 To 6
field(i) = Replace(field(i), " ", "")
HiField(j, i) = field(i)
Next
j = j + 1
Loop
SmartTags("szString_1") = HiField(0,1)
SmartTags("nValue_1") = HiField(1,1)
SmartTags("nValue_2") = HiField(2,1)
'Close file
f.Close
Set f = Nothing
Set fso = Nothing
ShowSystemAlarm "Readout of the data was successful!"
'// EOS /////////////////////////////////////////////////////////
The bolded Hifield information is what I am looking to stick into an array. I have 7 columns of information that I am looking to read for each row, and up to 1000 rows.
Is there a way I could use a structure so I could have the labels for each column (ie- date, torque, part #....)? Or I could live with sticking it in a array as 1a,1b,1c,1d,1e,1f,1g for each row incrementing the number. Any help would be appreciated thanks!
I am currently in the middle of a project and looking to read data from a .csv file on a server. I need to read this data and get it into the PLC so I can then compare the information for some necessary checks of validation. I have wrote a script already that can read the data, but I do not know how to save it to an array or structure and bring it into the PLC. Can any help point me in the right direction or provide any examples?
Here is my existing script:
'Declaration of local tags -
Dim fso, f, ts, Path, field, MyZf, i, j, k, HiField(2,6)
'Definition of local tags -
i=0
j=0
k=0
Path = "C:\Datalog1.csv"
'Error Routine -
On Error Resume Next
'Create object -
Set fso = CreateObject("Scripting.FileSystemObject")
If Err.Number <> 0 Then
ShowSystemAlarm "Error #" & CStr(Err.Number) & " " & Err.Description
Err.Clear
Exit Sub
End If
Set f = fspenTextFile(Path, 1, 0, -2)
If Err.Number <> 0 Then
ShowSystemAlarm "Error #" & CStr(Err.Number) & " " & Err.Description
Err.Clear
Exit Sub
End If
'Loop
Do While f.AtEndOfStream <> True
MyZf = f.ReadLine
field = Split(MyZf, ",")
For i=0 To 6
field(i) = Replace(field(i), " ", "")
HiField(j, i) = field(i)
Next
j = j + 1
Loop
SmartTags("szString_1") = HiField(0,1)
SmartTags("nValue_1") = HiField(1,1)
SmartTags("nValue_2") = HiField(2,1)
'Close file
f.Close
Set f = Nothing
Set fso = Nothing
ShowSystemAlarm "Readout of the data was successful!"
'// EOS /////////////////////////////////////////////////////////
The bolded Hifield information is what I am looking to stick into an array. I have 7 columns of information that I am looking to read for each row, and up to 1000 rows.
Is there a way I could use a structure so I could have the labels for each column (ie- date, torque, part #....)? Or I could live with sticking it in a array as 1a,1b,1c,1d,1e,1f,1g for each row incrementing the number. Any help would be appreciated thanks!