PIModuleVersionList Example

Option Explicit
  
Private Sub Command1_Click()
  Dim Mod1 As PIModule
  Dim Mod2 As PIModule
  Dim Mod3 As PIModule
  Dim versModule As IPIVersion
  Dim mvList As PIModuleVersionList
  Dim ptED1 As New PITime
  Dim ptED2 As New PITime
  Dim ptED3 As New PITime
  Dim ptED4 As New PITime
  Dim ptSearchStart As New PITime
  Dim ptSearchEnd As New PITime
  
  Dim Srv As Server
  
  Set Srv = Servers.DefaultServer
  Srv.Open
  
  On Error Resume Next
  Set Mod1 = Srv.PIModuleDB.PIModules.Add("Examples")
  Set Mod1 = Srv.PIModuleDB.PIModules.Item("Examples")
  
  Set Mod2 = Mod1.PIModules.Item("PIVersionTest6")
  On Error GoTo 0
  If Not Mod2 Is Nothing Then
     Mod1.PIModules.Remove Mod2 ' remove it and start over
  End If
  ' create module--this one has the default effective date of 1/1/1970 00:00:00 UTC
  Set Mod2 = Mod1.PIModules.Add("PIVersionTest6")
  Set versModule = Mod2.Version
  ptED1.LocalDate = #1/1/2001#
  ptED2.LocalDate = #1/1/2000#
  ptED3.LocalDate = #1/1/1999#
  ptED4.LocalDate = #1/1/1998#
  ' Create four new versions
  Set Mod3 = versModule.Copy(ptED1)
  Set Mod3 = versModule.Copy(ptED2)
  Set Mod3 = versModule.Copy(ptED3)
  Set Mod3 = versModule.Copy(ptED4)
  
  ptSearchEnd.LocalDate = #6/1/2000#
  ptSearchStart.LocalDate = #1/1/1998#
  
  Set mvList = versModule.Values(ptSearchStart, ptSearchEnd, btInside)
  MsgBox "ModuleList(btInside).Count = " & mvList.Count
  Set mvList = versModule.Values(ptSearchStart, ptSearchEnd, btOutside)
  MsgBox "ModuleList(btOutside).Count = " & mvList.Count
  End Sub
  
Enabling Operational Intelligence