COPA-DATA  



VBA All about VBA, automatic engineering, the zenon project wizard, ...

Reply
  #1  
Old 21st June 2010, 19:32
veselyd veselyd is offline
New Member
 
Join Date: 01.06.2010
Posts: 4
Unglücklich How to Update (Repaint or Refresh) screen after color change ?

Hello,
I have a question which is connected with VBA. I want to change background color of button on a screen, when I click on that.

First step is: Change Background - for example
obElem.BackColor = RGB(100,100,100)

Second step is: Update or repaint the new color of button. (To know which screen was selected).
Could you please help me how to do it ? (Something like obElem.Update ? )

Is there any function, or method ?
Reply With Quote
  #2  
Old 22nd June 2010, 01:08
markclemens's Avatar
markclemens markclemens is offline
Moderator
 
Join Date: 25.05.2007
Posts: 2,468
Default Re: How to Update (Repaint or Refresh) screen after color change ?

Visualbasic Code:
Sub change_color()
Dim myElem As Element
Dim myScrn As DynPicture
Set myScrn = thisProject.DynPictures.Item("a")
If Not myScrn Is Nothing Then
    Set myElem = myScrn.Elements.Item("aa")
    If Not myElem Is Nothing Then
        myElem.BackColor = RGB(89, 58, 12)
    End If
    myScrn.UpdateAll
End If
 
End Sub

You can use the UpdateAll method to redraw the sreen. However this change will only last while the screen is open. After a reopen the button will show it's original color again.

Generally I would recommend to use the dynamic background color through a variable, which can be configured in the editor, instead of doing this by VBA in the runtime.
__________________
do it your way!



Discover: Service Pages - zenon Product Family - Industry Solutions - local representative

Last edited by markclemens : 22nd June 2010 at 01:12.
Reply With Quote
  #3  
Old 22nd June 2010, 07:15
veselyd veselyd is offline
New Member
 
Join Date: 01.06.2010
Posts: 4
Default Re: How to Update (Repaint or Refresh) screen after color change ?

Thank you so much. I try it.
Reply With Quote
  #4  
Old 1st May 2013, 22:31
josefm josefm is offline
Moderator
 
Join Date: 20.07.2010
Location: Salzburg
Posts: 135
Send a message via Skype™ to josefm
Default Re: How to Update (Repaint or Refresh) screen after color change ?

Hello everyone,

I tried that solution and created a test project with a (hopeful enough) description.

Feel free to also expand the project and upload your ideas, I would appreciate it.

Following is the description that also can be found inside the project (Static Text Element on start screen).

For understanding how the project works:
---------------------------------------- zenon Logic ----------------------------------------
The zenon Logic (straton) project ist just creating random values.
Once it creates 3 random values (0-255) for the each of the colors ..
- red
- green
- blue
.. but it also creates out of those three the according hexadecimal value with a # before looking like e.g. #AA55FF or #29A09C.
As you can convert it back in VBA/VSTA/zenon Logic I thought it makes no sense to convert it back again in another module at the moment.
-------------------------------------------- VBA --------------------------------------------
The VBA does the main functionality in the project.
There are two functions that can be performed. Once the function "change_color()" and once the functions "Project_Active()", "zOLV_VariableChange()" and "Project_Inactive()" that belong together because this is the way we use the online container.
change_color()
This function mainly grabs the actual values and executes the coloring of the element via the function "Element.Background = RGB(R, G, B)".
It also has some mechanism that it should not crash if the screen or the element has the value "Nothing". At the end it updates all elements on the screen so that the new color is also displayed on the element.
Project_Active()
It creates the OnlineVariable container (OLC) and adds the three straton variables to the OLC. That the function works it also sets the global color variables to the initial value 0 (otherwise I would have errors on the first execution).
zOLV_VariableChange()
It's parameter is the changed variable. To make it easier to use more functionality it also uses the trigger variable (which is not nessecary). If the trigger equals 1 it does the coloring automatically otherwise it does not.
It grabs the changed values and depending on which of those variables was changed, it recolors the element using the actual changed color and the other two global color values. If no one of the colors changed it returns to the debug screen "No color changed!".
At the end it updates all elements on the screen so that the new color is also displayed on the element.
Project_Inactive()
Deactivates the "VariableChange" event and sets the OLC to nothing.
--------------------------------------- zenon Project ---------------------------------------
When you now start the zenon Runtime the zenon Logic project should start automatically.
Depending on the value of the variable next to "Change BG automatically" the values will be changed everytime the values are set new.
To make it happen faster/slow you have to change the "Timer" variable. The "RED", "GREEN", "BLUE" and "HEXVALUE" should usually just display the values, but you can also change them. On the "HEXVALUE" it won't take any effect but on "RED", "GREEN" and "BLUE" it will change the value and if you have the automatic mode "ON" then it also changes the color of the rectangle or if it is on "OFF" you have to click "Refresh Color".


Best regards
Attached Files
File Type: zip 2013-05-01 700_testproject.zip (232.7 KB, 13 views)

Last edited by josefm : 1st May 2013 at 22:38.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Update von 6.22 SP1 auf 6.5 SP0 martin@bmw General Support Requests 4 2nd June 2010 14:35
CEL- text color hoscillada General Support Requests 1 21st December 2009 11:38
how can I eliminate the black color as the flashing is begined.(combi element) michael_k General Support Requests 1 14th December 2009 03:23
Option button background color wrong russelldrown VBA 19 5th May 2009 13:51
Update pictures with VBA fabios VBA 5 21st July 2008 10:25


All times are GMT +1. The time now is 04:11.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.