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

Moving groups with VBA and Multi-state questions Options · View
jbugman
#1 Posted : Friday, January 28, 2011 10:13:20 AM
Rank: Newbie
Groups: Member

Joined: 1/28/2011
Posts: 3
Location: UK
Hello,

Info: Using PI 2.16. Have no access to newer software or SDK.

Part 1
What i want to do:
I want to group several squares and values together into one group and then move them upon clicking a button. Thus, this could then be used to "slide" in a what i need, before then being slid out again upon another button.

I am able to move a square using say:

Code:

square1.left -4


but a group doesnt have a name attached and hence i can't reference it in VBA.

Part 2
I use a lot of datasets in PI, but i cant multistate a dataset, so how can i do it please?

Thank you

James
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.
jbugman
#2 Posted : Friday, January 28, 2011 11:49:51 AM
Rank: Newbie
Groups: Member

Joined: 1/28/2011
Posts: 3
Location: UK
For instance if i do this:

Code:

Sub macro1()

rectangle.Selected = True
Rectangle1.Selected = True
SelectedSymbols.Group = "bob"


End Sub


It will group my two rectangles and then give me a "Run time error 438, Object doesnt support this property or method".

How can i then get hold of this group? Does it even reconise the name bob?

James
RJK Solutions
#3 Posted : Friday, January 28, 2011 1:55:32 PM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 617
Location: Cheshire, United Kingdom.
Hello James,

Wow, Processbook 2.16 is old stuff Tongue
Some sample code for creating a group, which forms a symbol of type "Composite", you would do the following:

Code:

Dim Comp As Composite

ThisDisplay.SelectedSymbols.RemoveAll
ThisDisplay.Rectangle1.Selected = True
ThisDisplay.Rectangle2.Selected = True

Set Comp = ThisDisplay.SelectedSymbols.Group
    Comp.Name = "Bob"

Debug.Print Comp.Name

Comp.Left = Comp.Left - 10


As for the datasets in 2.16 I am not sure without having it in front of me. When you select a symbol and go "Edit -> Multistate", where it has PI Point do you have a drop down to select a dataset? I am sure this was proably added to later version of ProcessBook...
Principal Consultant
Real-Time Data Management @ Wipro Technologies
jbugman
#4 Posted : Saturday, January 29, 2011 7:20:29 AM
Rank: Newbie
Groups: Member

Joined: 1/28/2011
Posts: 3
Location: UK
Hello,

After a bit of fiddling (debug.print doesnt seem to work!) , i got the following to work, allowing for it to be called from another module too.
Code:

Public Comp As Composite
Sub macro()
ThisDisplay.SelectedSymbols.RemoveAll
ThisDisplay.Rectangle.Selected = True
ThisDisplay.Rectangle1.Selected = True

Set Comp = ThisDisplay.SelectedSymbols.Group
    Comp.Name = "bob"

Debug.Print Comp.Name
MsgBox (Comp.Name)


Comp.Left = Comp.Left - 10


End Sub

Sub macro2()

ThisDisplay.SelectedSymbols.RemoveAll

MsgBox (Comp.Name)
Comp.Left = Comp.Left - 10


End Sub



[code]

Problem is now, if i close the processbook and open it up again, although the group is still there, its not named. Is there anyway to save the name permantley for that group? If not, do i have to (each time i open the book) set all the symbols into a group again?

In response to your question, how do i call that group With regarding datasets, when you go to symbol and multistate all you have is Server, tag search and tag, there is no way to get to the datasets.

On the flip side, is it possible therefore, do make say a value, a multistate using a dataset in VB, even if you have to copy and paste into vb the whole equation?

Ta

James
RJK Solutions
#5 Posted : Thursday, February 03, 2011 11:33:24 AM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 617
Location: Cheshire, United Kingdom.
You will need to re-establish your Composite variable to the group of symbols.
When you open your display get the symbol by...

Code:

Dim Comp As Composite
Set Comp = ThisDisplay.Symbols("bob")
...




Principal Consultant
Real-Time Data Management @ Wipro Technologies
Jboy
#6 Posted : Wednesday, April 13, 2011 7:08:40 PM
Rank: Member
Groups: Member

Joined: 4/12/2011
Posts: 10
Location: Uk
Me, just under a diferrent user name, sorry!

Er, after doing this:

Code:

Public Comp As Composite
Sub macro()
'ThisDisplay.SelectedSymbols.RemoveAll
'ThisDisplay.SelectedSymbols.All
'ThisDisplay.Symbols.Selected



'ThisDisplay.Rectangle.Selected = True
'ThisDisplay.Rectangle1.Selected = True

Set Comp = ThisDisplay.SelectedSymbols.Group
    Comp.Name = "bob"

Debug.Print Comp.Name
MsgBox (Comp.Name)


Comp.Left = Comp.Left - 10


End Sub

And then closing the book, reopen it and have this code running under this display
Code:

Private Sub Display_open()


Dim Comp As Composite
Set Comp = ThisDisplay.Symbols("bob")


End Sub


I get:
Runtime error:
-2147467259 (80004005)
Automation Error
Unspecfifed Error

Erm any clues?

J

Jboy
#7 Posted : Tuesday, April 26, 2011 10:09:52 AM
Rank: Member
Groups: Member

Joined: 4/12/2011
Posts: 10
Location: Uk
It would appear the above errors out on the line that refers to set comp as part

Any ideas?

J
Jboy
#8 Posted : Thursday, April 28, 2011 12:24:42 AM
Rank: Member
Groups: Member

Joined: 4/12/2011
Posts: 10
Location: Uk
More intresting info.

It would appear its the "setting" that VBA doesnt like. The error points to this line here:

Code:

Set Code = ThisDisplay.Symbols("bob")



However if I run this:

Code:


Sub testing()
Dim disp As Display
Set disp = ThisDisplay
Dim sym As Symbol



For Each sym In disp.Symbols
   
If sym.Name = "Composite9" Then

'Put it to make sure code sees the symbol
MsgBox "yes"
sym.Left = sym.Left - 10

End If
Next sym

End Sub

This works like a dream, I can even do it upon reopening the book

So to cap so far:
A) Its possible to move ANYTHING, including PI data
B) I am still stumped on how to "call" the symbols once the book is closed and reopened without looping through them as say above.

So, thoughts?

J


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.