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

Multiplie last 5 values and use in formula Options · View
mogwai
#1 Posted : Monday, January 02, 2012 2:18:43 PM
Rank: Member
Groups: Member

Joined: 4/8/2011
Posts: 16
Location: Denmark
Hi all

Is it possible to multipli/substract the last 5 values and use this in a formula?

If it is - how do you do it?
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.
squatty
#2 Posted : Tuesday, January 03, 2012 6:10:34 AM
Rank: Advanced Member

Groups: Member

Joined: 4/7/2011
Posts: 137
Location: KZN, South Africa
hi mogwai

It all depends in what environment you want to do this. In Excel you can do Compressed Data 5 data points backwards in time and do some simple excel stuff. In VBA you can use the x.data.recordedvaluesbycount(StartTime,count,dreverse,btinside) and write the values into an array and do what ever you want from here
mogwai
#3 Posted : Tuesday, January 03, 2012 6:37:22 AM
Rank: Member
Groups: Member

Joined: 4/8/2011
Posts: 16
Location: Denmark
Hi Smile

It is Process book I want to do this - I would prefer to use the process book formula Smile I would like to use last value, the 5th last value, the 10th last value and so on.

By the way do you know where you can find the VBA code you wrote? Are there a manual for this?
squatty
#4 Posted : Tuesday, January 03, 2012 6:46:06 AM
Rank: Advanced Member

Groups: Member

Joined: 4/7/2011
Posts: 137
Location: KZN, South Africa
OK so you want to do this using a dataset is that correct, good luck. I would recommend using the vba

You can get the sdk help files by going to your start menu->programs->pi system->about pi-sdk
When the sdk opens just go to the help section and select pi-sdk help
mogwai
#5 Posted : Tuesday, January 03, 2012 2:24:09 PM
Rank: Member
Groups: Member

Joined: 4/8/2011
Posts: 16
Location: Denmark
If it is not possible the way that I want can you then be more specific (with a example) how to make the VBA solution `? I am a bit confused if its the VBA in processbook or Excel - maybe it is the same in both cases Smile
squatty
#6 Posted : Wednesday, January 04, 2012 6:24:12 AM
Rank: Advanced Member

Groups: Member

Joined: 4/7/2011
Posts: 137
Location: KZN, South Africa
Private Sub test()

'***********DECLARE VARIABLES***********
Dim srv As PISDK.Server
Dim pt1 As PIPoint
Dim pv1 As PIValue
Dim pvs As PIValues

'***********SET MISSERVER TO DEFAULT***********
Set srv = PISDK.Servers.DefaultServer

'***********GET DATA***********
Set pt1 = srv.PIPoints("sinusoid")
Set pv1 = pt1.Data.Snapshot
Set pvs = pt1.Data.RecordedValuesByCount(Now(), 10, dReverse, btInside)

For Each pv1 In pvs
Debug.Print pv1.Value
Next

End Sub


Just make sure that you have the all the correct references in VBA,PI-SDK 1.3,PI-SDK Dialogs,PI-SDK Common and PITimeServer. Although you will not be using all of them in this example, I always add them anyway.
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.