Save and Fetch in Wincc Flex. (vb-script)

userxyz

Member
Join Date
May 2002
Location
any
Posts
2,768
Save:
Code:
Dim f, fs, file_path, file_name, file_name_path
On Error Resume Next
Set fs = CreateObject("filectl.filesystem")
Set f = CreateObject("filectl.file")
file_path= "\\PLC_102\CORRECTIES\"
file_name= CStr(SmartTags("ACTIVE BATCH.ORDER_DATABASE.ARTIKEL_NUMMER"))& ".csv"
file_name_path= file_path & file_name
If Err.Number <> 0 Then
ShowSystemAlarm "Error#" & CStr(Err.Number)&""& Err.Description
Err.Clear
Exit Sub
End If

If SmartTags("DB Ponsunit Data 300.Met_Zonder_Klemsysteem") Then
SmartTags("KlemValue")= 1
Else
SmartTags("KlemValue")= 0
End If 
f.open (file_name_path), 2 
f.Lineprint SmartTags("INSTELLING PONSUNIT.CORRECTIES.LINKS.ECS")
f.Lineprint SmartTags("INSTELLING PONSUNIT.CORRECTIES.LINKS.HOEK")
f.Lineprint SmartTags("INSTELLING PONSUNIT.CORRECTIES.LINKS.HOOGTE")
f.Lineprint SmartTags("INSTELLING PONSUNIT.CORRECTIES.RECHTS.ECS")
f.Lineprint SmartTags("INSTELLING PONSUNIT.CORRECTIES.RECHTS.HOEK")
f.Lineprint SmartTags("KlemValue")
f.Close

If Err.Number <> 0 Then
ShowSystemAlarm "Error#" & CStr(Err.Number)&""& Err.Description
Err.Clear
Exit Sub
End If 
Set f = Nothing
Set fs = Nothing
ShowSystemAlarm "Corrections storage was successful"

Fetch
Code:
Dim f, fs, file_path, file_name, file_name_path, DataSet, HiField(4,4), i, j, y
On Error Resume Next
Set fs = CreateObject("filectl.filesystem")
Set f = CreateObject("filectl.file")
file_path= "\\PLC_102\CORRECTIES\"
file_name= CStr(SmartTags("ACTIVE BATCH.ORDER_DATABASE.ARTIKEL_NUMMER"))& ".csv"
file_name_path= file_path & file_name
If Err.Number <> 0 Then
ShowSystemAlarm "Error#" & CStr(Err.Number)&""& Err.Description
Err.Clear
Exit Sub
End If 
If fs.dir(file_name_path)= "" Then
SmartTags("INSTELLING PONSUNIT.CORRECTIES.LINKS.ECS") = 0 
SmartTags("INSTELLING PONSUNIT.CORRECTIES.LINKS.HOEK") = 0
SmartTags("INSTELLING PONSUNIT.CORRECTIES.LINKS.HOOGTE") = 0
SmartTags("INSTELLING PONSUNIT.CORRECTIES.RECHTS.ECS") = 0
SmartTags("INSTELLING PONSUNIT.CORRECTIES.RECHTS.HOEK") = 0
SmartTags("KlemValue") = 0
Else
f.open file_name_path, 1 
For y = 0 To 5
i = 0
HiField(y,i) = f.LineInputString 
Next
SmartTags("INSTELLING PONSUNIT.CORRECTIES.LINKS.ECS") = HiField(0,0)
SmartTags("INSTELLING PONSUNIT.CORRECTIES.LINKS.HOEK") = HiField(1,0)
SmartTags("INSTELLING PONSUNIT.CORRECTIES.LINKS.HOOGTE") = HiField(2,0)
SmartTags("INSTELLING PONSUNIT.CORRECTIES.RECHTS.ECS") = HiField(3,0)
SmartTags("INSTELLING PONSUNIT.CORRECTIES.RECHTS.HOEK") = HiField(4,0)
SmartTags("KlemValue") = HiField(5,0) 
End If
If SmartTags("KlemValue")= 1 Then
SmartTags("DB Ponsunit Data 300.Met_Zonder_Klemsysteem")= True
Else
SmartTags("DB Ponsunit Data 300.Met_Zonder_Klemsysteem")= False
End If 

If Err.Number <> 0 Then
ShowSystemAlarm "Error#" & CStr(Err.Number)&""& Err.Description
Err.Clear
Exit Sub
End If 
f.close
Set f = Nothing
Set fs = Nothing
ShowSystemAlarm "Corrections fetching was successful"


Saving and fetching works, but..
When saving I get the 'Corrections fetching was successful' message.
When fetching I get 'Error #9, subscript out of range', while the fetch is done well...

Any ideas ?
 
more information

For y = 0 To 5
i = 0
HiField(y,i) = f.LineInputString
Next
SmartTags("INSTELLING PONSUNIT.CORRECTIES.LINKS.ECS") = HiField(0,0)
SmartTags("INSTELLING PONSUNIT.CORRECTIES.LINKS.HOEK") = HiField(1,0)
SmartTags("INSTELLING PONSUNIT.CORRECTIES.LINKS.HOOGTE") = HiField(2,0)
SmartTags("INSTELLING PONSUNIT.CORRECTIES.RECHTS.ECS") = HiField(3,0)
SmartTags("INSTELLING PONSUNIT.CORRECTIES.RECHTS.HOEK") = HiField(4,0)
SmartTags("KlemValue") = HiField(5,0)
End If


When I Do it with 4, then it works, like this:

For y = 0 To 4
i = 0
HiField(y,i) = f.LineInputString
Next
SmartTags("INSTELLING PONSUNIT.CORRECTIES.LINKS.ECS") = HiField(0,0)
SmartTags("INSTELLING PONSUNIT.CORRECTIES.LINKS.HOEK") = HiField(1,0)
SmartTags("INSTELLING PONSUNIT.CORRECTIES.LINKS.HOOGTE") = HiField(2,0)
SmartTags("INSTELLING PONSUNIT.CORRECTIES.RECHTS.ECS") = HiField(3,0)
SmartTags("INSTELLING PONSUNIT.CORRECTIES.RECHTS.HOEK") = HiField(4,0)
End If

Why with 4 no problems and with 0 to 5 I get an out of range ??
 
Hi there Combo

It had to be:
HiField(4,4) had to be HiField(5,5) in the declaration
because of:
SmartTags("KlemValue") = HiField(5,0)

hence out of range, right?

I dint understood the meaning as well as need of
Set f = CreateObject("filectl.file")

Can you shed some light here?
 
:)

Indeed, I was reading in cell 5,0, but the declaration was only untill sell 4,4. That is the reason what I got 'Out of range' message and it didn't read 5,0.
Works fine now with 5,5 declaration.




Hi there Combo

It had to be:
HiField(4,4) had to be HiField(5,5) in the declaration
because of:
SmartTags("KlemValue") = HiField(5,0)

hence out of range, right?

I dint understood the meaning as well as need of
Set f = CreateObject("filectl.file")

Can you shed some light here?

Set f = CreateObject("filectl.file") is needed because I use the read line:

f.open file_name_path, 1


Set f = CreateObject("filectl.file")
saying that the declaration f is some kind of library for doing things with files.

first say that f = file control
then use f.open to open the file
,1 = reading (see vb script reference in wincc flex)
 
OK Combo thanks
Apparently this is new thing for me.
I use the following method for writeline:

Code:
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile("E:\Data.csv")
Set ts = f.OpenAsTextStream(8, -2)
ts.WriteLine "whatever"
ts.Close

Actually this is handy reference which I use while dealing with script.
And it doesn't mention of f = CreateObject("filectl.file").
 
Difference

Your code is for win xp, mine for win ce !!


OK Combo thanks
Apparently this is new thing for me.
I use the following method for writeline:

Code:
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile("E:\Data.csv")
Set ts = f.OpenAsTextStream(8, -2)
ts.WriteLine "whatever"
ts.Close

Actually this is handy reference which I use while dealing with script.
And it doesn't mention of f = CreateObject("filectl.file").
 

Similar Topics

Hi; First of all, I am sorry that my post is not relevant with this forum. I have recently purchased Samsung cell phone. I have alreay saved...
Replies
1
Views
75
Hello! I have a datablock in a PLC witch contains about 700 variables. I must save this data once a day on a Windows PC in a XML or CSV file. Eg...
Replies
1
Views
487
Hello Folks! I have an issue and its very often but in this case i applied all the tricks and tips that i always do in similiar issues but in this...
Replies
2
Views
776
I'm a bit stuck again... See the redacted picture. At the moment, pressing F7 saves the "live" laser measurement into the boxes indicated by the...
Replies
9
Views
1,076
On my HMI-1200, I'm trying to assign the image of a floppy disk ("save" icon) to a function key. I couldn't find one in the default drop-down...
Replies
5
Views
596
Back
Top Bottom