dts256 Posted February 1, 2016 Share Posted February 1, 2016 Hi, For some reason the attached code doesn't work properly. The variable for the radiobutton seems to be being set to the number of code lines above it in the first instance, so nothing happens if I select the first radio button. However, it works if the second radio button is selected. How do I correct this please ? I'm new to Autoit, only started with it a cople of days ago, so go easy Test1.au3 Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted February 1, 2016 Moderators Share Posted February 1, 2016 (edited) @dts256 welcome to the forum. The reason you're having problems is you assigned the same variable name to both radio buttons. Assign them different names (e.g. $radio1 and $radio2) and see what that buys you Edit: I see what you're trying to do, loop through the radio buttons. Give me a second to throw an example up that shows that. Edited February 1, 2016 by JLogan3o13 "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...
dts256 Posted February 1, 2016 Author Share Posted February 1, 2016 Wow, thank you for such a quick response. I'll try it, just now and let you know how I get on. Link to comment Share on other sites More sharing options...
BrewManNH Posted February 1, 2016 Share Posted February 1, 2016 #include <GUIConstantsEx.au3> ;Constants for GUI Events ; Hides tray icon ;#NoTrayIcon ; create the GUI. $win = GUICreate("Choose Program") ;Show the GUI GUISetState(@SW_SHOW) ; Create the radio buttons GUICtrlCreateGroup("Programs", 8, 50, 140, 200) $radio1 = GUICtrlCreateRadio("Notepad", 20, 100) $radio2 = GUICtrlCreateRadio("Calculator", 20, 120) ;Create the OK button $okButton = GUICtrlCreateButton("OK", 300, 360) ; Continuous Loop to check for GUI Events While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $okButton Select Case GUICtrlRead($radio1) = $GUI_CHECKED RunWait("Notepad.exe") Case GUICtrlRead($radio2) = $GUI_CHECKED RunWait("Calc.exe") EndSelect EndSelect WEnd Your 2 radio buttons are being assigned to the same variable, so you're overwriting the control ID from the first radio control when you created the second. 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...
Moderators JLogan3o13 Posted February 1, 2016 Moderators Share Posted February 1, 2016 BrewManNH beat me to the example. Is that more in line with what you're trying to do, or do you expect to have a number of radio buttons and want to loop through them to see which is checked? "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...
dts256 Posted February 1, 2016 Author Share Posted February 1, 2016 @BrewManNH Thank you for your quick reply. I've just tried that, the gui just closes after clcking ok, whichever radio button I select. Link to comment Share on other sites More sharing options...
BrewManNH Posted February 1, 2016 Share Posted February 1, 2016 Just now, dts256 said: I've just tried that, the gui just closes after clcking ok, whichever radio button I select. No it doesn't. Not the script that I posted at least. 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...
dts256 Posted February 1, 2016 Author Share Posted February 1, 2016 There's something weird going on with my Scitec. Whenver I copy and paste any code into a new window, none of the formatting shows up and also the "Go" button is greyed out. So I made the changes that I could see in your script to mine and the gui just closes after I've selected a button and pressed ok. I know that's a far cry from what I actually said, so apologies for that and I guess I must have missed one or more of your changes. What I'd actually like to have is just a single variable to check, rather than multiple ones, as in the attached code, from http://www.gamerzplanet.net/threads/autoit-some-easy-tuts.236602/ which works when youve added the button back in. FromWeb.au3 Link to comment Share on other sites More sharing options...
dts256 Posted February 1, 2016 Author Share Posted February 1, 2016 Just figured out why no formatting etc showed up. I accidentally saved the file as .au instead of .au3 @BrewManNH Your modifications to my code work like a charm, thank you for that and sorry for the misunderstanding earlier. @JLogan3o13 Thank you for your help so far. If it's possible, I'd still like to be able to do thisusing just one variable though, like in the code I attached earlier. Link to comment Share on other sites More sharing options...
BrewManNH Posted February 1, 2016 Share Posted February 1, 2016 That script will never work as intended, it has the same mistake your original script does, it's reusing the $radio variable, so the only control it will EVER be able to read is the last one created. 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...
dts256 Posted February 1, 2016 Author Share Posted February 1, 2016 Actually, you're right. Didn't realise it before you said, but the age group is always the same one, 41-50, I think it was, whatever button is selected, and I hadn't noticed that before. So, now at least I understand why my original code doesn't work. I've learnt something, so I'm happy. Thnak you both for your help. 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