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

VBA to Modify Trend Pen Colors Options · View
milesUK
#1 Posted : Friday, January 22, 2010 4:04:30 PM
Rank: Advanced Member
Groups: Member

Joined: 5/28/2009
Posts: 70
Location: Cheshire, UK
I am trying to standardise my displays with VBA and I have tried the following approach
Quote:
Public Sub Standardise_Display_Styles(ByVal TheDisplay As Display)

Dim sym As Symbol
Dim e As TrendElement

For Each sym In TheDisplay.Symbols

If sym.Type = pbSymbolTrend Then

sym.BackgroundColor = RGB(0, 0, 0) 'OK

'standardise trend colours
For Each e In sym.TrendElements '************* ERRORS WITH 'OBJECT DOESN'T SUPPORT THIS PROPERTY OR METHOD' ********
e.Color = RGB(255, 0, 0)
Next e

End If

Next sym

End Sub
and some variants but feel that I need to drill down like this sym.TrendFormat.TrendElements.TrendElement but I just cannot get the syntax right.

Could anyone advise me please?

Regards,

Miles
MilesUK
ProcessBook v3.0.15.3
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.
Michael
#2 Posted : Friday, January 22, 2010 4:42:01 PM
Rank: Advanced Member
Groups: Member

Joined: 12/3/2009
Posts: 71
Location: Germany/Pennsylvania
Miles,

you have to get the format definition first, change the elements and then to set it.


Dim sym As Symbol
Dim tr As Trend
Dim e As TrendElement
Dim tf As TrendFormat
Set sym = ThisDisplay.Symbols(1)
Set tr = sym
Set tf = tr.GetFormat 'GET
For Each e In tf.Elements
e.Color = vbRed
Next e
tr.SetFormat tf 'SET

In this case each element will be red.
RJK Solutions
#3 Posted : Friday, January 22, 2010 4:42:41 PM
Rank: Administration

Groups: Administration

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

Key to this one is to use the TrendFormat object with the pbTrendELEMENT enumeration. Example below.

Code:

Sub test()

Dim TheTrend As Trend
Set TheTrend = ThisDisplay.Symbols("Trend1")

Dim TF As TrendFormat
Set TF = TheTrend.GetFormat
    TF.Elements(pbBackGround).Color = pbBlack
    TF.Elements(pbHAxis).Color = pbWhite
    TF.Elements(pbText).Color = RGB(0, 0, 255)

    TF.Elements(pbPen1).Color = pbGreen
    TF.Elements(pbPen1).LineStyle = pbLSolid
    TF.Elements(pbPen1).LineWidth = pbThin
       
    TheTrend.SetFormat TF
   
Set TF = Nothing
Set TheTrend = Nothing

End Sub


EDIT: I see Michael and I thought about this at the same time BigGrin ThumbsUp
Principal Consultant
Real-Time Data Management @ Wipro Technologies
milesUK
#4 Posted : Monday, January 25, 2010 9:14:27 AM
Rank: Advanced Member
Groups: Member

Joined: 5/28/2009
Posts: 70
Location: Cheshire, UK
Micheal / Rhys, Only 40 seconds apart! How the great minds think alike.

Thank you both of you. I'm getting something working at last.

Miles
MilesUK
ProcessBook v3.0.15.3
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.