gottygolly Posted March 4, 2014 Share Posted March 4, 2014 (edited) Hello, Melba23 if you're reading this you might be able to answer this a little better than someone else because this is your code. Heres the code. #include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 500, 500) $cLabel = GUICtrlCreateLabel("100", 10, 10, 400, 40) GUICtrlSetFont($cLabel, 24) $cButton_Add5 = GUICtrlCreateButton("Add 5", 10, 100, 80, 30) $cButton_Min10 = GUICtrlCreateButton("Minus 10", 110, 100, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton_Add5 GUICtrlSetData($cLabel, Number(GUICtrlRead($cLabel)) + 5) Case $cButton_Min10 GUICtrlSetData($cLabel, Number(GUICtrlRead($cLabel)) - 10) EndSwitch WEnd Now when you hit 0 you can keep going below 0, such as -10, -20, -30, -40, -50. Is there a way to prevent this? In my code I managed to make it popup a msgbox when you hit 0 or below and it exits the scripts but you can keep going below 0 if you don't click the button to set off the msgbox function. Any help would be amazing (It's probably something stupid) Edited March 4, 2014 by gottygolly Link to comment Share on other sites More sharing options...
Moderators Solution JLogan3o13 Posted March 4, 2014 Moderators Solution Share Posted March 4, 2014 Why not just add an If statement to keep it above 0? #include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 500, 500) $cLabel = GUICtrlCreateLabel("100", 10, 10, 400, 40) GUICtrlSetFont($cLabel, 24) $cButton_Add5 = GUICtrlCreateButton("Add 5", 10, 100, 80, 30) $cButton_Min10 = GUICtrlCreateButton("Minus 10", 110, 100, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton_Add5 GUICtrlSetData($cLabel, Number(GUICtrlRead($cLabel)) + 5) Case $cButton_Min10 If GUICtrlRead($cLabel) > 10 Then GUICtrlSetData($cLabel, Number(GUICtrlRead($cLabel)) - 10) Else GUICtrlSetData($cLabel, Number(0)) EndIf EndSwitch WEnd gottygolly 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
gottygolly Posted March 4, 2014 Author Share Posted March 4, 2014 Thought it was something dumb Thanks. Link to comment Share on other sites More sharing options...
gottygolly Posted March 5, 2014 Author Share Posted March 5, 2014 Sorry for posting here again I figured it's better just to repost on here instead of making a whole new one. with this code expandcollapse popup#include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 500, 500) $amount = "100" $cLabel = GUICtrlCreateLabel("%" & $amount, 10, 10, 400, 40) GUICtrlSetFont($cLabel, 24) $cButton_Add5 = GUICtrlCreateButton("Add 5", 10, 100, 80, 30) $cButton_Min10 = GUICtrlCreateButton("Minus 10", 110, 100, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton_Add5 GUICtrlSetData($cLabel, Number(GUICtrlRead($cLabel)) + 5) Case $cButton_Min10 If GUICtrlRead($cLabel) > 10 Then GUICtrlSetData($cLabel, Number(GUICtrlRead($cLabel)) - 10) Else GUICtrlSetData($cLabel, Number(0)) EndIf EndSwitch WEnd If I were to change the "100" in the label to ("%" & $amount) why doe it change it back to "0" without the "%"? I don't care about how it changes back to 0, I just want to be able to change the variable $amount without deleting the "%" in front of it. Any ideas? Link to comment Share on other sites More sharing options...
BrewManNH Posted March 5, 2014 Share Posted March 5, 2014 Because GUICtrlSetData on a label erases the previous contents with what you're writing to the label. If you want it formatted the same, you have to write it in exactly the same format every time you update the label. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
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