VB Script question

userxyz

Member
Join Date
May 2002
Location
any
Posts
2,768
I have this script:

Code:
 Historian
SetDataRecordToPLC "Batches", SmartTags("Record"), hmiOn, Null
If Err.Number <> 0 Then
 ShowSystemAlarm "Error #" & CStr(Err.Number) & " " & Err.Description
 Err.Clear
 Exit Sub
End If
DeleteDataRecord "Batches", SmartTags("Record"), hmiOn, hmiOn, Null
If Err.Number <> 0 Then
 ShowSystemAlarm "Error #" & CStr(Err.Number) & " " & Err.Description
 Err.Clear
 Exit Sub
End If

Historian is this script:

Code:
 Dim fso, f, ts, DataSet, Path, Dataformat
On Error Resume Next
Path = "C:\"
Set fso = CreateObject("Scripting.FileSystemObject")
SmartTags("File") = Path & SmartTags("BATCHES.Info._klantnr") & ".csv"
Dataformat = "Datum" & ";" & "Tijd" & ";" & "Klantnaam" & ";" & "Klantnummer" & ";" & "Ordernummer" & ";" & "Regelnummer" & ";" & "Artikelnummer" & ";" & "Leverdatum" & ";" & "Matrijs Hoek 1" & ";" & "Matrijs Hoek 2" & ";" & "Buistype" & ";" & "Buislengte" & ";" & "Buisdiameter" & ";" & "Buismateriaal" & ";" & "Wenslengte" & ";" & "Wenshoek 1" & ";" & "Wenshoek 2" & ";" & "Wensaantal" & ";"		 
DataSet = (Date & ";" & Time & ";" & SmartTags("BATCHES.Info._klantnaam") & ";" & SmartTags("BATCHES.Info._klantnr") & ";" & SmartTags("BATCHES.Info._ordernr") & ";" & SmartTags("BATCHES.Info._regelnr") & ";" & SmartTags("BATCHES.Info._artikelnr") & ";" & SmartTags("BATCHES.Info._leverdatum") & ";" & SmartTags("BATCHES.Info._matrijs_hoek_1") & ";" & SmartTags("BATCHES.Info._matrijs_hoek_2") & ";" & SmartTags("BATCHES.Buis._type") & ";" & SmartTags("BATCHES.Buis._lengte") & ";" & SmartTags("BATCHES.Buis._diameter") & ";" & SmartTags("BATCHES.Buis._materiaal") & ";" & SmartTags("BATCHES.Wens._lengte") & ";" & SmartTags("BATCHES.Wens._hoek_1") & ";" & SmartTags("BATCHES.Wens._hoek_2") & ";" & SmartTags("BATCHES.Wens._aantal"))
 
If Err.Number <> 0 Then
 ShowSystemAlarm "Error #" & CStr(Err.Number) & " " & Err.Description
 Err.Clear
 Exit Sub
End If
If Not fso.FileExists(SmartTags("File")) Then
 fso.CreateTextFile SmartTags("File")
	Set f = fso.GetFile(SmartTags("File"))
 Set ts = f.OpenAsTextStream(8,-2)
 ts.WriteLine Dataformat
 ts.WriteLine ""
 ts.WriteLine DataSet
 ts.Close
Else
 Set f = fso.GetFile(SmartTags("File"))
 Set ts = f.OpenAsTextStream(8,-2)
 ts.WriteLine DataSet
 ts.Close
End If
If Err.Number <> 0 Then
 ShowSystemAlarm "Error #" & CStr(Err.Number) & " " & Err.Description
 Err.Clear
 Exit Sub
End If
Set ts = Nothing
Set f = Nothing
Set fso = Nothing
ShowSystemAlarm "Storage of the data was successful!"


The problem is...

The second script is called in the first script at Line 1,

I want to log my tags with historian, after that the rest of the code may send the data of the chosen record to the plc and delete the one on the panel.

Problem is, I get the values in historian that have been set by the rest of the code...

this means that historian script is not executed first ???

Why not, I setted it on Line 1 before my other code...
 
Are these tags being 'Read' from a device? if so, you may need to force an actual update of the tags before using them.

For diagnostics, either write messages to a log file at every step, or pop up a message box.

As a matter of course, I always include some diagnostic messages at the entry and exit of any routine, to make tracking proper flow easy.
 
...

They are read from a PLC, and the recipesystem is also using these...

I need to log the previeus batch when I new one is called




rdrast said:
Are these tags being 'Read' from a device? if so, you may need to force an actual update of the tags before using them.

For diagnostics, either write messages to a log file at every step, or pop up a message box.

As a matter of course, I always include some diagnostic messages at the entry and exit of any routine, to make tracking proper flow easy.
 
Well, don't know if this helps, but I just finished a logging/reporting system for some of our lines here, and the best way I've found to deal with update times and synchronization seems to be the following:

Create a datablock for your current values and an identical one for logged values.

When the batch is reset, copy the current value block into the logged value block. Set a flag after the copy to tell the HMI to log the data.

In the HMI code, when it sees the flag, do a forced read/update of the 'logged values' block, and then write it out to your report.

Timing is critical, as is ensuring that the values are completely refreshed from the PLC, don't rely on a data server to ensure that they are not stale.
 

Similar Topics

I have a circle that I want to have different colors depending on the value of two different tags. If it was one tag with a simple bit or...
Replies
9
Views
5,941
This is another question for the Red Lion guys out there. I am working on the custom website for my Data Station Plus and have a question about...
Replies
2
Views
1,836
I want to change color or make a animation of some thing in Wincc, and I was write a code in Global Script C(that is a application in WinCC). But...
Replies
0
Views
2,590
Hi, folks! I'm banging my head against the wall again, trying to find a reasonable way to "see" 3 words in each of 4 PLCs (CPM2B...
Replies
5
Views
2,715
Hey everybody, I'm trying to use a WinCC script to set several variables that have a similar naming convention. (In the real application...
Replies
0
Views
2,316
Back
Top Bottom