【AB技术篇】FTview Trend中如何通过VBA编程添加FTHistorian的变量


Function Add(Name As String, LineDesc As String, EngUnits As String, Min As Single, Max As Single, [DatalogModelName], [Historian]) As Pen


[Historian]-必须VB布尔细目真(n.b. 不是“真”或1)

Dim pen1 As Pen
Dim Ps As Pens
Set Ps = Trend1.Pens
Set pen1 = Ps.Add("MyTagName", "MyDescription", "My Eng Units", 0, 100, "", True)

'Create a new display in FactoryTalk View SE
'Create a Trend object and call it "Trend1"

'Create a button and call it "GetPenList" then enable VBA and paste the following code under the GetPenList_Released() event:
'Go to Tool References in the VBE and add the following references:
' Microsoft ActiveX Data Objects 2.8 Library
' Microsoft ActiveX Data Objects Recordset 2.8 Library
Private Sub GetPenList_Released()
' create the ADO connection object
Dim objCN As ADODB.Connection
Set objCN = CreateObject("ADODB.Connection")

' change the Data Source to be the server name for your system
objCN.Open "Provider = PIOLEDB; Data Source = ***"
If (Err.Number <> 0) Then
MsgBox "connectionfailed" 'handle error here
End If

' query string will select only the tag name for all tags (*).
Dim strSQL As String
strSQL = "SELECT tag FROM pipoint..pipoint2 WHERE tag LIKE '*'"

' Create a recordset using the connection and the query
Dim objRS As ADODB.Recordset
Set objRS = objCN.execute(strSQL)
If Err.Number <> 0 Then
MsgBox "recordset not created" 'handle error here
End If

If objRS.EOF Then
MsgBox "no records returned"
End If

'loop through the recordset and add each tagname to the combobox
Do While Not objRS.EOF
ComboBox1.AddItem objRS("tag")

Set objRS = Nothing
Set objCN = Nothing
End Sub

'Add a Microsoft Forms combo box and past in the following code.
'N.B. make sure target systems have MS Forms 2.0 installed
'When a tag is selected in the Combobox this code will add it as a pen to the trend.
Private Sub ComboBox1_Change()
Dim pen1 As Pen
Dim Ps As Pens
Set Ps = Trend1.Pens
Set pen1 = Ps.Add(ComboBox1.SelText, "Temp 1", "Deg F", 0, 100, "", True)
End Sub