YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

SOLVED! - Creating Dataset with VBA and adding to trend Options · View
jc113883
#1 Posted : Tuesday, December 21, 2010 12:45:54 AM
Rank: Member
Groups: Member

Joined: 10/7/2009
Posts: 14
I use the following code to programatically create a new display, add a trend, create a new dataset and then add the dataset to the trend.

The trend is created however the dataset comes up as invalid. To get it working, I open the trend to edit the calculation, click once in the expression box and then once in the column name box and then save. The problem seems to be that the column name is not being set when the dataset is created, making it invalid. If you remove all the code about creating the trend and just use the code to create the dataset, the same thing happens - if I manually try to add it to the trend, it says invalid dataset when I select it. I still need to click in the expression box and then the column name box to get it to work.

Code:
Sub Add_DS_to_Trend()

Dim MyDatasets As Datasets
Dim MyDataset As PIExpressionDataset

Set NewDisplay = Application.Displays.Add("New Trend")

Set trnd = Application.ActiveDisplay.Symbols.Add(pbSymbolTrend)

trnd.Width = Application.ActiveDisplay.ViewWidth
trnd.Height = Application.ActiveDisplay.ViewHeight



Set MyDatasets = Application.ActiveDisplay.Datasets
Set MyDataset = MyDatasets.Add("NewCalcDataSet", Nothing, True, 1, True, pbDatasetPIExpression)
Set MyDataset = MyDatasets.GetDataset("NewCalcDataSet")

MyDataset.Expression = "'sinusoid'*2"
MyDataset.RefreshInterval = 3600
MyDataset.ColumnName = "Value"
MyDataset.Interval = "10m"
MyDatasets.SetDataset MyDataset

trnd.AddTrace "NewCalcDataSet.Value"

End Sub
Sponsor  
 

OSIsoft vCampus is a subscription-based, online offering that consists of providing everything people need to develop applications on the PI System.
We invite you to take a "tour" of the OSIsoft Virtual Campus - also feel free to consult the FAQ  or contact OSIsoft vCampus for more details.
jc113883
#2 Posted : Tuesday, December 21, 2010 2:25:27 AM
Rank: Member
Groups: Member

Joined: 10/7/2009
Posts: 14
Solved - Turns out I had to also include this line:
Code:
        MyDataset.ServerName = "myservername"
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.