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

Add方法的TrendX笔集合具有以下语法:

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

对于FactoryTalkHistorianSE笔所需的参数应设置,如下所示:

名称作为字符串-这是字符串中称为标签FactoryTalkHistorian
[DatalogModelName]-必须VBNULL字符串“”
[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)
工作ViewSE示例显示如何得到一个列表的Historian标签名称到一个记录集,并添加一个作为一个笔在趋势:

'********
'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")
objRS.MoveNext
Loop

Set objRS = Nothing
objCN.Close
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