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

Taking Action After a Mode Change Options · View
mek
#1 Posted : Sunday, August 08, 2010 12:26:54 PM
Rank: Newbie
Groups: Member

Joined: 8/8/2010
Posts: 2
Location: US
Hi,
I'm new to the forum and to programming. I was wondering if there is a way in PI that you can do something after a mode change.

For example, I would like when the mode changes from build to run I would like to execute a If statement.
But within PI you are controlled by the drop down menu and the actions confined in them, and I don't see the option of AfterModeChange or BeforeModeChange.

I thought I found code that could help me in the VBA help menu, but my PI processbook doesn't recognize the code. (Specifically "CApp")




Here is what I found in VBA help, "Example for Application ModeChange Events":


Public WithEvents test As Application

Private Sub test_AfterModeChange(ByVal bRunMode As Boolean)
Debug.Print "AfterModeChanged"
End Sub

Private Sub test_BeforeModeChange(bCancel As Boolean)
Debug.Print "BeforeModeChanged"
End Sub

This code is in the Display Object:

Dim app As CApp

Private Sub Display_Open()
Set app = New CApp
Set app.test = Application
End Sub


I would appreciate any help.
Thank you,
Marie
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.
RJK Solutions
#2 Posted : Monday, August 09, 2010 1:27:24 PM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 612
Location: Cheshire, United Kingdom.
Hi Marie,

Welcome to the forum.

"CApp" refers to a Class Module that is added to the VBA Project for your display.
To get this to work you need to:

- Go to VBA editor (Alt+F11).
- Select "Insert" then "Class Module".
- Name this "CApp".
- Paste in the code:
Code:

Public WithEvents test As Application


Private Sub test_AfterModeChange(ByVal bRunMode As Boolean)

Debug.Print "AfterModeChanged"

End Sub


Private Sub test_BeforeModeChange(bCancel As Boolean)

Debug.Print "BeforeModeChanged"

End Sub

- Within the "ThisDisplay" object, paste the code:
Code:

Dim app As CApp


Private Sub Display_Open()

Set app = New CApp

Set app.test = Application

End Sub

- Put the VBA cursor somewhere in the "Display_Open" event code (just click in it).
- Hit "F5" to run through the code (simulates when you open the display).

Now when you change mode you will get some messages in your immediate window.

Hope this helps.
Principal Consultant
Real-Time Data Management @ Wipro Technologies
mek
#3 Posted : Friday, August 13, 2010 9:50:24 AM
Rank: Newbie
Groups: Member

Joined: 8/8/2010
Posts: 2
Location: US
Oh thank you. This helped a lot. I didn't know to put in a class module I had to go to "Insert" > "Class Module". Thank you again.
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.