AnsweredAssumed Answered

VBA to create and plot Dataset dependent on Userform input

Question asked by SLethen on Apr 1, 2019
Latest reply on Apr 1, 2019 by SLethen

Hi

 

I'm trying to write a macro that will create a dataset, where the dataset expression depends on the value input to a text box in a UserForm. When the macro plots this dataset on an existing trend however, the trace label displays No Data.

 

I'm using the code below:

 

Private Sub CommandButton1_Click()
     Dim MyDatasets As Datasets

     Dim MyDataset As PIExpressionDataset
     Dim TagFilter As String
     Dim MyTrend As Trend

 

     Set TagFilter = TextBox1.Value

 

     Set MyDatasets = ThisDisplay.Datasets
     Set MyDataset = MyDatasets.Add("FilterDataset", Nothing, True, 1, True, pbDatasetPIExpression)
     Set MyDataset = MyDatasets.GetDataset("FilterDataset")

     MyDataset.ServerName = "MyServer"
     MyDataset.Expression = "If 'VariableTag' > TagFilter Then 'TagToDisplay' Else NoOutput()"
     MyDataset.RefreshInterval = 60000
     MyDataset.ColumnName = "Value"
     MyDataset.Interval = "10m"
     MyDataset.Description = "Filtered Dataset"
     MyDatasets.SetDataset MyDataset

     Set MyTrend = ThisDisplay.Trend1

     MyTrend.AddTrace ("FilterDataset.Value")

 

     UserForm1.Hide

 

End Sub

 

The code works if I change the dataset expression to equal 'TagFilter' only, so it looks like the issue is with the dataset expression I'm using.

 

Thanks

Outcomes