Novark Posted October 9, 2009 Posted October 9, 2009 (edited) 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 October 9, 2009 by Novark
martin Posted October 9, 2009 Posted October 9, 2009 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.
JRowe Posted October 9, 2009 Posted October 9, 2009 (edited) 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 October 9, 2009 by JRowe [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center]
JRowe Posted October 9, 2009 Posted October 9, 2009 Orrrrr, martin can beat me to the punch [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center]
Novark Posted October 9, 2009 Author Posted October 9, 2009 Ack, of course. Why didn't I think of that Thank you, martin and JRowe!
Emiel Wieldraaijer Posted October 11, 2009 Posted October 11, 2009 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
BrettF Posted October 11, 2009 Posted October 11, 2009 Why make it a function? You don't have to, it really depends on what your doing. Its up to the OP to make it a function or not... Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
JRowe Posted October 12, 2009 Posted October 12, 2009 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. [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center]
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now