Jump to content

Real time label updating


Novark
 Share

Recommended Posts

How do I go about updating a label to display a progress bar's data value?

I'm using a basic MessageLoop format as such:

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
GUICtrlSetData($LBL_Percent, GUICtrlRead($Progress1) & "%") ;Displays 'X%' where X is the data value of the progress bar
WEnd

The problem here is that the label flickers due to the loop cycling over and over. I had a sleep command in there, and it worked fine, but I read in the manual that adding a sleep command in the loop is a bad idea.

How do you work around this and allow the label to be updated in real-time to match the progress bar? Is there a type of "DataChange" event that I can apply to the progress bar, and call a function that updates the label?

Any ideas?

Thanks.

P.S. Totally unrelated, but is there a quick and easy method to change the main-body background color of a Tab-Control (For each individual tab)?

Edited by Novark
Link to comment
Share on other sites

How do I go about updating a label to display a progress bar's data value?

I'm using a basic MessageLoop format as such:

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
GUICtrlSetData($LBL_Percent, GUICtrlRead($Progress1) & "%") ;Displays 'X%' where X is the data value of the progress bar
WEnd

The problem here is that the label flickers due to the loop cycling over and over. I had a sleep command in there, and it worked fine, but I read in the manual that adding a sleep command in the loop is a bad idea.

How do you work around this and allow the label to be updated in real-time to match the progress bar? Is there a type of "DataChange" event that I can apply to the progress bar, and call a function that updates the label?

Any ideas?

Thanks.

P.S. Totally unrelated, but is there a quick and easy method to change the main-body background color of a Tab-Control (For each individual tab)?

Try setting th elabel text only if it needs to be changed, not every time round the loop. That will probably stop the flicker.

EG

$NewText = ....
If GuiCtrlRead($Label1) <> $NewText then GuiCtrlSetData($label1,$NewText)

to change the background of a tab you can create a child window the size of and in the the position of the tab, set the child window colour, place all the controls for that tab on the child and only show the child when that tab is selected. There is an example by aec somewhere.

That won't change the tab for the page but you could add a label for that and there is a nice example somewhere by Valik for that.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Only update the label if the value changes, so put a conditional statement around your label update. This means you have to monitor what your value was before the change, so you need another variable:

$myValue = 0
$myValueHistory = 1
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
$myValue = GUICtrlRead($Progress1)
If $myValue <> $myValueHistory Then
GUICtrlSetData($LBL_Percent, $myValue & "%") ;Displays 'X%' where X is the data value of the progress bar
EndIf

$myValueHistory = $myValue

WEnd
Edited by JRowe
Link to comment
Share on other sites

Link to comment
Share on other sites

It already is a function... I really have a problem seeing any benefits to making an existing function into a function that does the same thing as the original function. That's like... dressing a dog in a dog suit.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...