angel666 Posted June 10, 2011 Share Posted June 10, 2011 Hi there, This is my first post in the forum. I have been working on some AutoIt scripts developing some tools for myself and ran into a scenario where I wanted radio controls with checkbox functionality at the same time retaining their properties. I implemented it in the following way. I do not consider myself an expert in AutoIt (casual dev searching AutoIt help and user forums whenever I need some info). This is definitely not the best way to implement. Please let me know if there's a better way. I am posting this in case someone might find it useful. expandcollapse popup;;globals $rad1Checked = 0 $rad2Checked = 0 $rad3Checked = 0 .... .... While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $RadioRad1 $rad2Checked = 0 $rad3Checked = 0 If $rad1Checked = 1 Then $rad1Checked = 0 GUICtrlSetState ($RadioRad1, $GUI_UNCHECKED) ElseIf $rad1Checked = 0 Then $rad1Checked = 1 GUICtrlSetState ($RadioRad1, $GUI_CHECKED) EndIf Case $RadioRad2 $rad1Checked = 0 $rad3Checked = 0 If $rad2Checked = 1 Then $rad2Checked = 0 GUICtrlSetState ($RadioRad2, $GUI_UNCHECKED) ElseIf $rad2Checked = 0 Then $rad2Checked = 1 GUICtrlSetState ($RadioRad2, $GUI_CHECKED) EndIf Case $RadioRad3 $rad1Checked = 0 $rad2Checked = 0 If $rad3Checked = 1 Then $rad3Checked = 0 GUICtrlSetState ($RadioRad3, $GUI_UNCHECKED) ElseIf $rad3Checked = 0 Then $rad3Checked = 1 GUICtrlSetState ($RadioRad3, $GUI_CHECKED) EndIf Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 10, 2011 Share Posted June 10, 2011 INCDNR (Incomplete code, did not run.) In general though, if you find yourself repeating the exact same lines of code like that you are missing something. Here, you could use GuiOnEventMode and have just one handler function for all the radio buttons. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
angel666 Posted June 10, 2011 Author Share Posted June 10, 2011 INCDNR (Incomplete code, did not run.)Yeah, I just posted the relevant code so it wont run as-is.In general though, if you find yourself repeating the exact same lines of code like that you are missing something. Here, you could use GuiOnEventMode and have just one handler function for all the radio buttons.I knew events was one way to go about. I am not a fan of code repetition or using globals etc (I used three in my snippet), but I just wanted to present the idea and get some feedback on if there was a better way (looks like events is probably the best way to go).Thanks. 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