PIBatches example

 

Option Explicit

Private Sub Command1_Click()
Dim myServer As Server
Dim myBatch1 As PIBatch
Dim myBatch2 As PIBatch
Dim myCampaign As PICampaign
Dim startTime As New PITime
Dim endTime As New PITime
Dim myCampList As PICampaignList
Dim findCamp As PICampaign
'
Set myServer = PISDK.Servers.DefaultServer
myServer.Open
'
' Add some PIBatches
'
endTime.SetToCurrent
startTime.UTCSeconds = endTime.UTCSeconds - 1 ' 1 second batches
Set myBatch1 = myServer.PIBatchDB.Add("Batch1", "Product1", "Recipe1", startTime, endTime)
Set myBatch2 = myServer.PIBatchDB.Add("Batch2", "Product2", "Recipe2", startTime, endTime)
'
' Create a PICampaign
'
Set myCampaign = myServer.PIBatchDB.PICampaignDB.Add("Campaign1", startTime, endTime)
'
' Insert the PIBatches into the PICampaign.PIBatches collection
'
myCampaign.PIBatches.Insert myBatch1
myCampaign.PIBatches.Insert myBatch2

MsgBox "Number of PIBatches in PICampaign: " & myCampaign.PIBatches.Count, , "Count"
MsgBox "PICampaignID for " & myBatch1.BatchID & " = " & myCampaign.CampaignID
'
' Search for the PICampaign
'
Set myCampList = myServer.PIBatchDB.PICampaignDB.PICampaignSearch(startTime, endTime)
Set findCamp = myCampList.Item(1)
MsgBox "Found CampaignID = " & findCamp.CampaignID
End Sub

 

Enabling Operational Intelligence