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

Change fill color on click Options · View
aosterta
#1 Posted : Thursday, January 19, 2012 4:45:36 PM
Rank: Newbie
Groups: Member

Joined: 1/5/2012
Posts: 2
Hi. This is my first time dealing with VBA and I have a very basic problem.
In my display I have two rectangles, "A" and "B". I want to be able to change the fill color of A or B to RGB (0,255,0) by clicking on it in run mode. However, by clicking on one, I want the other's fill color to change to RGB (255,255,255).

So basically, one will be green and one will be white at all times and I can change which is green by clicking on it.
I've been working with the code unsuccessfully and any help would be greatly appreciated.

Thank you,
Alex
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.
JB1
#2 Posted : Thursday, January 19, 2012 5:43:04 PM
Rank: Newbie
Groups: Member

Joined: 7/5/2011
Posts: 9
Location: Massachusetts
To make this work, you need to enable scripting on the rectangles in your display. Right click on the rectangles and choose enable scripting. Then copy and paste the code below into your vba editor.
Code:
Private Sub Rectangle1_Click(ByVal lvarX As Long, ByVal lvarY As Long)
    Call colorSwitch
End Sub

Private Sub Rectangle2_Click(ByVal lvarX As Long, ByVal lvarY As Long)
    Call colorSwitch
End Sub

Private Sub colorSwitch()
    If Rectangle1.FillColor = 65280 Then
        Rectangle1.FillColor = 16777215
        Rectangle2.FillColor = 65280
    Else
        Rectangle1.FillColor = 65280
        Rectangle2.FillColor = 16777215
    End If
End Sub

One thing to check would be the names of your rectangles. In the VBA editor goto view, then properties window. Select your rectangles on the display and check the name property in the properties window. The name of the subs above should reflect the names of your rectangles. For example: if the name of your rectangle is "Rectangle6", then the sub above should be named Rectangle6_click not Rectangle1_click.

Hopefully this answers your question. Good luck.
aosterta
#3 Posted : Friday, January 20, 2012 9:55:50 PM
Rank: Newbie
Groups: Member

Joined: 1/5/2012
Posts: 2
Thank you! I appreciate the help
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.