AnsweredAssumed Answered

VBA Sample code to lista PI Batch on UserForm ListView

Question asked by Allan Ferreira on Sep 27, 2016
Latest reply on Oct 14, 2016 by Dan Fishman

Hi,

 

Someone have a sample code to fill na userform listview with PI batch data?

 

I tryed to use the sample on PI SDK help but doesn´t work. I don´t retrieve data from Batch. I user PIModule, PI Batch, PI BatchList, etc.

 

nowadays, I am using this code, but with PI API...

 

Dim apistat As Long
Dim valid As Long
Dim clicks As Integer
Dim column As Variant
Private Sub btnAbout_Click()
    Sobre.Show
End Sub
Private Sub btnCancel_Click()
    Unload Batchs
    End
End Sub
Private Sub btnCxn_Click()
    Dim iNumber As Long
    Dim sUnit As String * 81
    Dim i As Long
    
    apistat = pilg_connectdlg(0)
     
    cmbUnit.Clear
    i = 0
    apistat = piba_getunit(sUnit, Len(sUnit), i, iNumber)
    For i = 0 To iNumber - 1
        apistat = piba_getunit(sUnit, Len(sUnit), i, iNumber)
        cmbUnit.AddItem (sUnit)
    Next i
    
    cmbUnit.ListIndex = 0
End Sub
Private Sub btnOK_Click()
    Dim i As Integer
    Dim box As Variant
    
    If (lstBatches.SelectedItem = "") Then
        box = MsgBox("Selecione um Rolo!", vbExclamation, "Aviso")
        Exit Sub
    Else
        ActiveSheet.Range("Rolo").Value = lstBatches.SelectedItem.Text
        ActiveSheet.Range("ProdAtual").Value = lstBatches.SelectedItem.SubItems(1)
        ActiveSheet.Range("StTime").Value = lstBatches.SelectedItem.SubItems(2)
        ActiveSheet.Range("ETime").Value = lstBatches.SelectedItem.SubItems(3)
        If chkReteste.Value Then
            ActiveSheet.Range("Reteste").Value = 1
        Else
            ActiveSheet.Range("Reteste").Value = 0
        End If
    End If
    
    Unload Batchs
    Application.wait (1)
    End
End Sub
Private Sub btnStart_Click()
    Dim BQuery As New PIBatchView
    Dim inicialdate As String
    Dim finaldate As String
    Dim i As Integer
    
    lstBatches.ListItems.Clear
    
    BQuery.QueryKind = pibvBatch
    BQuery.UnitCond = pibvLike
    BQuery.UnitTest = cmbUnit.Value
    BQuery.TimeFrom = ptoe(dtpData.Value + 1)
    BQuery.TimeTo = ptoe(dtpData.Value)
    BQuery.direction = pibvLast
    BQuery.MaxCount = 100
    BQuery.CompleteOnly = True
    BQuery.Run
    
    For i = 1 To BQuery.count
        lstBatches.ListItems.Add = BQuery.Results(i).Id
        lstBatches.ListItems(i).SubItems(1) = BQuery.Results(i).product
        lstBatches.ListItems(i).SubItems(2) = Format(BQuery.Results(i).StartTime, "dd-mmm-yy hh:mm:ss")
        lstBatches.ListItems(i).SubItems(3) = Format(BQuery.Results(i).EndTime, "dd-mmm-yy hh:mm:ss")
    Next i
    
    Set BQuery = Nothing
End Sub
Private Sub frmDatas_Click()
End Sub
Private Sub UserForm_Initialize()
    Dim iNumber As Long
    Dim sUnit As String * 81
    Dim i As Long
        
    cmbUnit.Clear
    
    i = 0
    apistat = piba_getunit(sUnit, Len(sUnit), i, iNumber)
    For i = 0 To iNumber - 1
        apistat = piba_getunit(sUnit, Len(sUnit), i, iNumber)
        cmbUnit.AddItem (sUnit)
    Next i
    
    If apistat = 0 Then cmbUnit.ListIndex = 1
    dtpData.Value = DateValue(Now)
    lstBatches.ListItems.Clear
    clicks = 0
End Sub
Private Sub lstBatches_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
    Dim i As Integer
      
    lstBatches.Sorted = True
    
    If (column = ColumnHeader) And (clicks Mod 2 = 0) Then
        lstBatches.SortOrder = lvwAscending
        clicks = clicks + 1
    ElseIf (column = ColumnHeader) And (clicks Mod 2 = 1) Then
        lstBatches.SortOrder = lvwDescending
        clicks = clicks + 1
    Else
        lstBatches.SortOrder = lvwAscending
        clicks = 1
    End If
    lstBatches.SortKey = ColumnHeader.index - 1
    lstBatches.Refresh
    lstBatches.Sorted = False
    column = ColumnHeader
End Sub
Private Sub UserForm_Terminate()
CalculoAutomatico
End Sub

I want to replace this code... Any tip?

 

Thanks in advance.

Outcomes