PIBatchDB / PIBatch  / PIUnitBatches Example

 

Option Explicit

Private Sub Command1_Click()

    Dim PIServer As PISDK.Server
    Dim BatchDB As PISDK.PIBatchDB
    Dim BatchList As PISDK.PIBatchList
    Dim Batch As PISDK.PIBatch
    Dim SearchStart As New PITime
    Dim SearchEnd As New PITime

    Set PIServer = PISDK.Servers.Item("Localhost")

    Set BatchDB = PIServer.PIBatchDB

' Search from one hour ago to current time
    SearchEnd.SetToCurrent
    SearchStart.UTCSeconds = SearchEnd - 3600#
    Set BatchList = BatchDB.PIBatchSearch(SearchStart, SearchEnd)

    ListView1.ListItems.Clear
    ListView1.ColumnHeaders.Add , , "BatchID", ListView1.Width / 4
    ListView1.ColumnHeaders.Add , , "Product", ListView1.Width / 4
    ListView1.ColumnHeaders.Add , , "RecipeName", ListView1.Width / 4
    ListView1.ColumnHeaders.Add , , "Start Time", ListView1.Width / 4
    ListView1.ColumnHeaders.Add , , "End Time", ListView1.Width / 4
    ListView1.ColumnHeaders.Add , , "Unique ID", ListView1.Width / 4
    ListView1.View = lvwReport

    Dim mItem As ListItem
    Dim UnitBatches As PIUnitBatches
    Dim UnitBatch As PIUnitBatch
    For Each Batch In BatchList
        Set mItem = ListView1.ListItems.Add
        mItem.Text = Batch.BatchID
        mItem.SubItems(1) = Batch.Product
        mItem.SubItems(2) = Batch.Recipe
        mItem.SubItems(3) = Batch.StartTime
        mItem.SubItems(4) = Batch.EndTime
        mItem.SubItems(5) = Batch.UniqueID

        For Each UnitBatch In Batch.PIUnitBatches
            Set mItem = ListView1.ListItems.Add
            mItem.Text = UnitBatch.BatchID
            mItem.SubItems(1) = UnitBatch.Product
            mItem.SubItems(2) = UnitBatch.ProcedureName
            mItem.SubItems(3) = UnitBatch.StartTime
            mItem.SubItems(4) = UnitBatch.EndTime
            mItem.SubItems(5) = UnitBatch.UniqueID
        Next UnitBatch
    Next Batch

End Sub

Enabling Operational Intelligence