Jump to content
Sign in to follow this  
Novark

Real time label updating

Recommended Posts

Novark

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

Share this post


Link to post
Share on other sites
martin

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.

Share this post


Link to post
Share on other sites
JRowe

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

Share this post


Link to post
Share on other sites
JRowe
Novark

Ack, of course. Why didn't I think of that :)

Thank you, martin and JRowe!

Share this post


Link to post
Share on other sites
Emiel Wieldraaijer

Martin method is the right one

but you should make it a function

Func _GUICtrlSetData($iCtrlID, $sData)

If GUICtrlRead($iCtrlID, 1) <> $sData Then GUICtrlSetData($iCtrlID, $sData)

EndFunc

So you can used _GUICtrlSetData instead of GUICtrlSetData

Best regards,

Emiel


Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites
BrettF

Share this post


Link to post
Share on other sites
JRowe

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.

Share this post


Link to post
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
Sign in to follow this  

×