anub13 Posted March 27, 2017 Share Posted March 27, 2017 Hi, I am new to Auto It, I am trying to figure out how to get value from selected radio button, here is my code Global $chkSomething, $CatA= 'Category A', $CatB='Category B' Select Case GUICtrlRead($radio1) = 1 $chkSomething = $CatA Case GUICtrlRead($radio2) = 1 $chkSomething = $CatB EndSelect ; I tried to call the value here $categ = GUICtrlRead($chkSomething) $errInfo = $errInfo & "~category='" & $categ & "'" & @CRLF what did I do wrong? Please advise. Link to comment Share on other sites More sharing options...
232showtime Posted March 27, 2017 Share Posted March 27, 2017 could you post your whole script? ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon. Link to comment Share on other sites More sharing options...
anub13 Posted March 27, 2017 Author Share Posted March 27, 2017 Would be too long here, and there is reason I cant attach the file, is there any code that needed to understand my problem better? Link to comment Share on other sites More sharing options...
KickStarter15 Posted March 27, 2017 Share Posted March 27, 2017 Hi anub13, Before you can get the value of each radio, you need to set it first to true. I have the same issue as what you have before and i have it below. Hope it helps you. Try: Example() Func Example() ; Initialize a Local variable. Global $errInfo, $chkSomething While 1 $CatA= 'Category A' $CatB='Category B' Select Case GUICtrlRead($Radio1) = 1 $chkSomething = $CatA Case GUICtrlRead($Radio2) = 1 $chkSomething = $CatB EndSelect WEnd EndFunc ;==>Example Func Button1Click() ; I tried to call the value here $categ = $chkSomething MsgBox("", "Category selected", $categ) Return $errInfo = $errInfo & "~category='" & $categ & "'" & @CRLF Exit Or Example() Func Example() ; Initialize a Local variable. Global $errInfo, $chkSomething While 1 $CatA= 'Category A' $CatB='Category B' Select Case GUICtrlRead($Radio1) = 1 $chkSomething = $CatA MsgBox("", "Radio 1 selected", $chkSomething) Exit Case GUICtrlRead($Radio2) = 1 $chkSomething = $CatB MsgBox("", "Radio 2 selected", $chkSomething) Exit EndSelect WEnd EndFunc ;==>Example $errInfo = $errInfo & "~category='" & $categ & "'" & @CRLF Exit Better to provide more sample code so that this forum can help you more. Trust me. Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
anub13 Posted March 27, 2017 Author Share Posted March 27, 2017 Hi, Sorry for late reply, please find attached file for detailed code. Thanks for the reply Kickstarter15, appreciated, but not working. MyFile.au3 Link to comment Share on other sites More sharing options...
Subz Posted March 27, 2017 Share Posted March 27, 2017 Basic Example: #include <GUIConstantsEx.au3> Example() Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate("Example") $idRadio1 = GUICtrlCreateRadio("Wisecloud", 90, 160, 185, 25) $idRadio2 = GUICtrlCreateRadio("Internet Speed Etc", 90, 180, 185, 25) Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idOK If GUICtrlRead($idRadio1) = $GUI_CHECKED Then MsgBox(0,'', GUICtrlRead($idRadio1, 1)) If GUICtrlRead($idRadio2) = $GUI_CHECKED Then MsgBox(0,'', GUICtrlRead($idRadio2, 1)) EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example Link to comment Share on other sites More sharing options...
anub13 Posted March 27, 2017 Author Share Posted March 27, 2017 Hi Subz, Thanks for the reply.. very appreciated, have you take look at whole script? Link to comment Share on other sites More sharing options...
Subz Posted March 27, 2017 Share Posted March 27, 2017 Yes, I had a quick glance at the script, wasn't able to run completely as I didn't have the required software installed. Not 100% sure if my post above helped at all but wasn't sure what you were hoping to achieve. Link to comment Share on other sites More sharing options...
anub13 Posted March 27, 2017 Author Share Posted March 27, 2017 As I said above, I am trying to figure out how to get value from selected radio button, then call/retrieve/pass that value to another Please take a look at this code in the file if $isAdminVersion=0 then $ASDFGInfo = $ASDFGInfo & @CRLF & " Ticket Tags:" & @CRLF $ASDFGInfo = $ASDFGInfo & "~userphone='" & GUICtrlRead($txtPhone) & "'" & @CRLF $ASDFGInfo = $ASDFGInfo & "~submitterphone='" & GUICtrlRead($txtPhone) & "'" & @CRLF dim $MachineID $MachineID = KaseyaIni($gKIniFile,"SERVER COMMUNICATIONS","User_Name","NotFound") $ASDFGInfo = $ASDFGInfo & "~machineid='" & $MachineID & "'" & @CRLF dim $OrgGroups $OrgGroups= StringSplit($MachineID,".") dim $OrgGroupIndex $OrgGroupIndex = UBound($OrgGroups) - 1 $ASDFGInfo = $ASDFGInfo & "~organization='" & $OrgGroups[$OrgGroupIndex] & "'" & @CRLF dim $EmailUser $EmailUser = GUICtrlRead($txtEmailAddress) $EmailUser = StringMid($EmailUser,1,StringInStr($EmailUser,"@") - 1) $ASDFGInfo = $ASDFGInfo & "~username='" & $EmailUser & "'" & @CRLF dim $categ $categ = GUICtrlRead($chkPatrol) $ASDFGInfo = $ASDFGInfo & "~category='" & $categ & "'" & @CRLF $ASDFGInfo = $ASDFGInfo & "~afterhour='" & $AfterHour & "'" & @CRLF endif Return $ASDFGInfo I am trying to input it on $categ, but always showing the output as '0' Link to comment Share on other sites More sharing options...
Subz Posted March 27, 2017 Share Posted March 27, 2017 Right think I understand, $chkPatrol isn't a Gui Control so you shouldn't be using GuiCtrlRead($chkPatrol), you should just have $categ = $chkPatrol Link to comment Share on other sites More sharing options...
232showtime Posted March 27, 2017 Share Posted March 27, 2017 to lazy to run the code... have you tried this? $vRadio = ControlGetText($Form1_1, "", $radio1) ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon. Link to comment Share on other sites More sharing options...
anub13 Posted March 27, 2017 Author Share Posted March 27, 2017 1 minute ago, 232showtime said: to lazy to run the code... have you tried this? $vRadio = ControlGetText($Form1_1, "", $radio1) Will try 4 minutes ago, Subz said: Right think I understand, $chkPatrol isn't a Gui Control so you shouldn't be using GuiCtrlRead($chkPatrol), you should just have $categ = $chkPatrol Will try Thanks, be right back soon. Link to comment Share on other sites More sharing options...
anub13 Posted March 27, 2017 Author Share Posted March 27, 2017 Hi Subz, it gives nothing... Hi 232Showtime, It does the trick! But I wonder why showing always to internet speed etc and when I change the option its still that option, any ideas? I Put them like this dim $categ $categ = ControlGetText($Form1_1, "", $radio1) $categ = ControlGetText($Form1_1, "", $radio2) $ASDFGInfo = $ASDFGInfo & "~category='" & $categ & "'" & @CRLF Sorry i am complete newb This code is from previous worker, and I just learned it. Link to comment Share on other sites More sharing options...
Subz Posted March 27, 2017 Share Posted March 27, 2017 Global $chkPatrol, $Wise= 'Wisecloud', $Internet ='Internet Speed Etc' Select Case GUICtrlRead($radio1) = 1 $chkPatrol = $Wise Case GUICtrlRead($radio2) = 1 $chkPatrol = $Internet EndSelect Based upon the code in your script, $chkPatrol = $Wise or $Internet if the Radio is checked, so if you run MsgBox(0, "", $chkPatrol) after the code above it should return either one of those values. Link to comment Share on other sites More sharing options...
KickStarter15 Posted March 27, 2017 Share Posted March 27, 2017 (edited) @anub13 How about having it this way: Global $chkPatrol, $Wise= 'Wisecloud', $Internet ='Internet Speed Etc' Select Case GUICtrlRead($Radio1) = 1 $chkSomething = $Wise Case GUICtrlRead($Radio2) = 1 $chkSomething = $Internet EndSelect If $chkSomething = true Then $categ = $chkSomething MsgBox("","Selected",$categ) Return Endif Edited March 27, 2017 by KickStarter15 Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
anub13 Posted March 27, 2017 Author Share Posted March 27, 2017 Hi Subz, I tried it like this, did I do anything wrong? It still show nothing Select Case GUICtrlRead($Radio1) = 1 $chkPatrol = $Wise MsgBox(0, "", $chkPatrol) Case GUICtrlRead($Radio2) = 1 $chkPatrol = $Internet MsgBox(0, "", $chkPatrol) EndSelect dim $categ $categ = $chkPatrol $ASDFGInfo = $ASDFGInfo & "~category='" & $categ & "'" & @CRLF Hi Kickstarter15, Showing error , please find attached file for detail Link to comment Share on other sites More sharing options...
Subz Posted March 27, 2017 Share Posted March 27, 2017 Here is the code using my Gui example above: expandcollapse popup#include <GUIConstantsEx.au3> Example() Func Example() ; Create a GUI with various controls. Local $chkPatrol, $Wise= 'Wisecloud', $Internet ='Internet Speed Etc' Local $hGUI = GUICreate("Example") $idRadio1 = GUICtrlCreateRadio("Wisecloud", 90, 160, 185, 25) $idRadio2 = GUICtrlCreateRadio("Internet Speed Etc", 90, 180, 185, 25) Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idOK Select Case GUICtrlRead($idRadio1) = 1 $chkPatrol = $Wise Case GUICtrlRead($idRadio2) = 1 $chkPatrol = $Internet EndSelect $categ = $chkPatrol $ASDFGInfo = "" $ASDFGInfo = $ASDFGInfo & "~category='" & $categ & "'" & @CRLF MsgBox(0,'', $ASDFGInfo) EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example Link to comment Share on other sites More sharing options...
232showtime Posted March 27, 2017 Share Posted March 27, 2017 (edited) @anub13 Include this in your script, outside the function. Global $chkPatrol, $Wise = 'Wisecloud', $Internet = 'Internet Speed Etc' While 1 If GUICtrlRead($radio1) = $GUI_CHECKED Then $chkPatrol = $Wise MsgBox(0, "", $chkPatrol) EndIf If GUICtrlRead($radio2) = $GUI_CHECKED Then $chkPatrol = $Internet MsgBox(0, "", $chkPatrol) EndIf Sleep(100) WEnd Edited March 27, 2017 by 232showtime EDIT: Above Example is correct. IDK why its not working for you. ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon. Link to comment Share on other sites More sharing options...
KickStarter15 Posted March 27, 2017 Share Posted March 27, 2017 (edited) @anub13 Both Subz and 232Showtime's code are doing correctly as what you need. Same as with the below code: #include <GUIConstantsEx.au3> $Form1 = GUICreate("Form", 190, 100, 282, 200) GUISetBkColor(0xA0A0A0) GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") $Radio1 = GUICtrlCreateRadio("Radio 1", 25, 40, 55, 17) $Radio2 = GUICtrlCreateRadio("Radio 2", 100, 35, 65, 25) GUISetState(@SW_SHOW) Example() Func Example() ; Initialize a Local variable. Global $ASDFGInfo, $chkPatrol, $categ While 1 $CatA= 'Wisecloud' $CatB='Internet Speed Etc' Select Case GUICtrlRead($Radio1) = 1 $chkPatrol = $CatA Case GUICtrlRead($Radio2) = 1 $chkPatrol = $CatB EndSelect ; Value prompted here as msgbox If $chkPatrol = true Then $categ = $chkPatrol $ASDFGInfo = $ASDFGInfo & "~category='" & $categ & "'" & @CRLF MsgBox("","",$ASDFGInfo) Exit EndIf WEnd EndFunc ;==>Example Exit Func Form1Close() Exit EndFunc Now if these codes won't work at your testing, please emphasized what you really wan't to achieve. These codes will get the value of what radio button was being selected, all these three codes from Subz and 232Showtime and mine has the same functions and desired output. KS15 Edited March 27, 2017 by KickStarter15 Edited: Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
Trong Posted March 27, 2017 Share Posted March 27, 2017 Autoit Radio Example: expandcollapse popup;~ #include <GUIConstantsEx.au3> Global Const $GUI_EVENT_CLOSE = -3 Global Const $GUI_CHECKED = 1 ;~ #include <MsgBoxConstants.au3> Global Const $MB_ICONWARNING = 48 Global $hGUI = GUICreate("Autoit Radio :)", 568, 104, 763, 195) Global $idRadio1 = GUICtrlCreateRadio("Radio 1 Text", 32, 24, 113, 17) GUICtrlSetState($idRadio1, $GUI_CHECKED) Global $idRadio2 = GUICtrlCreateRadio("Radio 2 Text", 184, 24, 113, 17) Global $idButtonCheck = GUICtrlCreateButton("Check", 376, 16, 169, 33) Global $idLabelStatus = GUICtrlCreateLabel("", 40, 64, 508, 17) GUISetState(@SW_SHOW) Global $chkSomething, $cSelect, $CatA = 'Category A', $CatB = 'Category B' Global $idMsg _CheckGUIinput(0) While 1 $idMsg = GUIGetMsg() Switch $idMsg Case $GUI_EVENT_CLOSE Exit Case $idRadio1 _CheckGUIinput(0) Case $idRadio2 _CheckGUIinput(0) Case $idButtonCheck _CheckGUIinput(1) EndSwitch Sleep(10) WEnd Func _CheckGUIinput($showMsg = 0) If GUICtrlRead($idRadio1) = $GUI_CHECKED Then $chkSomething = $CatA $cSelect = GUICtrlRead($idRadio1, 1) Else $chkSomething = $CatB $cSelect = GUICtrlRead($idRadio2, 1) EndIf ConsoleWrite('You Select: "' & $cSelect & '" & Cat is: ' & $chkSomething & @CRLF) GUICtrlSetData($idLabelStatus, 'You Select: "' & $cSelect & '" & Cat is: ' & $chkSomething) If $showMsg Then Return MsgBox($MB_ICONWARNING, "Info", 'You Select: "' & $cSelect & '" & Cat is: ' & $chkSomething) EndFunc ;==>_CheckGUIinput Regards, 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