PIAliases Example

Option Explicit

Private Sub Command1_Click()
  Dim strTemp As String
  Dim Alias As PIAlias
  Dim Point As PIPoint
  Dim Module As PIModule
  Dim myAliasList As New PIAliasList
  
  PISDK.Servers.DefaultServer.Open
  
  ' First time in, create the module. Disregard if it exits 
  On Error Resume Next
  Set Module = PISDK.Servers.DefaultServer.PIModuleDB.PIModules.Add("PIAliasTest1")
  On Error GoTo 0
  Set Module = PISDK.Servers.DefaultServer.PIModuleDB.PIModules.Item("PIAliasTest1")
  Set Point = PISDK.Servers.DefaultServer.PIPoints.Item("BA:Temp.1")
  On Error Resume Next
  ' Create the aliases, disregard if it exists 
  Set Alias = Module.PIAliases.Add("Temperature", Point)
  Set Alias = Module.PIAliases.Item("Temperature")
  On Error GoTo 0
  myAliasList.Insert Alias
  
  Set Point = PISDK.Servers.DefaultServer.PIPoints.Item("BA:Level.1")
  
  On Error Resume Next
  ' Create the aliases, disregard if it exists 
  Set Alias = Module.PIAliases.Add("Level", Point)
  Set Alias = Module.PIAliases.Item("Level")
  On Error GoTo 0
  myAliasList.Insert Alias
  
  Set Point = PISDK.Servers.DefaultServer.PIPoints.Item("BA:Conc.1")
  On Error Resume Next
  ' Create the aliases, disregard if it exists 
  Set Alias = Module.PIAliases.Add("Concentration", Point)
  Set Alias = Module.PIAliases.Item("Concentration")
  On Error GoTo 0
  myAliasList.Insert Alias
  
  List1.Clear
  For Each Alias In Module.PIAliases
   strTemp = Alias.Name + " \\" + Alias.DataSource.Server.Name + "\" + Alias.DataSource.Name
   List1.AddItem strTemp
  Next Alias
  
  List2.Clear
  For Each Alias In myAliasList
   strTemp = Alias.Name + " \\" + Alias.DataSource.Server.Name + "\" + Alias.DataSource.Name
   List2.AddItem strTemp
  Next Alias
  
End Sub
  
Enabling Operational Intelligence