Sign in to follow this  
Followers 0
myksharma

Set radio button as selected by default

10 posts in this topic

Hey everyone.

looking for some quick answer to this--

I'm using couple of radio buttons created via GUICtrlCreateRadio function.

My intent is to have one of those selected by default upon program launch, can this be achieved & if yes, how.

thanks in advance..

Share this post


Link to post
Share on other sites



You'd have to set the state of the Radio Button

Here is an example from the help file:

Local $idRadio2 = GUICtrlCreateRadio("Radio 2", 10, 40, 120, 20)
GUICtrlSetState($idRadio2, $GUI_CHECKED)

:)

Share this post


Link to post
Share on other sites

Thanks Saudumm.

this works fine however I'm importing the radio button selection as a variable in a .vbs script that executes after my program finishes.

Now, the program has radio button#2 selected as default however when I directly finish the program, it doesn't show me the value of radio button#2 in the .vbs script.

If I select radio button#1 then it works as expected.

Share this post


Link to post
Share on other sites

Koda Section--

 
$OS = GUICtrlCreateRadio("Select OS Only", 110, 312, 129, 25)
GUICtrlSetFont(-1, 10, 800, 0, $GUIFont)
$OSPlusApps = GUICtrlCreateRadio("Select OS & Apps", 280, 312, 129, 25)
GUICtrlSetFont(-1, 10, 800, 0, $GUIFont)
GUICtrlSetState($OSPlusApps, $gui_checked)
 
 
 
 
From the function--
 
        $msg  = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
Case $msg = $OS
                $strOS = True
$strOSPlusApps = False
            Case $msg = $OSPlusApps
                $strOSPlusApps = True
   $strOS = False
 
 
 
Vbs filewrite-- 
 
IF $strOS Then FileWriteLine($OutFile, "TSEnv(" & Chr(34) & "OSOnly" & Chr(34) & ") = " & Chr(34) & $strOS & Chr(34))
    IF $strOS Then FileWriteLine($OutFile, "TSEnv(" & Chr(34) & "OSWithApps" & Chr(34) & ") = " & Chr(34) & $strOSPlusApps & Chr(34))
    IF $strOSPlusApps Then FileWriteLine($OutFile, "TSEnv(" & Chr(34) & "OSWithApps" & Chr(34) & ") = " & Chr(34) & $strOSPlusApps & Chr(34))
    IF $strOSPlusApps Then FileWriteLine($OutFile, "TSEnv(" & Chr(34) & "OSOnly" & Chr(34) & ") = " & Chr(34) & $strOS & Chr(34))

Share this post


Link to post
Share on other sites

Please try this Vbs Filewrite. It checks the State of your Radio Buttons, sets the variables and writes to your vbs-file.

Switch $GUI_CHECKED
    Case GUICtrlRead($OS)
        $strOS = True
        $strOSPlusApps = False
    Case GUICtrlRead($OSPlusApps)
        $strOS = False
        $strOSPlusApps = True
EndSwitch

FileWriteLine($OutFile, "TSEnv(" & Chr(34) & "OSOnly" & Chr(34) & ") = " & Chr(34) & $strOS & Chr(34))
FileWriteLine($OutFile, "TSEnv(" & Chr(34) & "OSWithApps" & Chr(34) & ") = " & Chr(34) & $strOSPlusApps & Chr(34))

Share this post


Link to post
Share on other sites

$msg  = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Switch $GUI_CHECKED
                Case GUICtrlRead($OS)
                    $strOS = True
                    $strOSPlusApps = False
                Case GUICtrlRead($OSPlusApps)
                    $strOS = False
                    $strOSPlusApps = True
            EndSwitch
             ;Case $msg = $OS
                         ;$strOS = True
             ;$strOSPlusApps = False
                         ;Case $msg = $OSPlusApps
                         ;$strOSPlusApps = True
             ; $strOS = False
             
              Case $msg = $Finish

It didn't enumerate the results in the .vbs output--

TSEnv("OSOnly") = ""
TSEnv("OSWithApps") = ""

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

You have to put my Switch-Statement outside of your Select-Statement just before your Filewriteline. Something like this:

$msg  = GUIGetMsg()
Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Finish
        ;Something else
EndSelect


Switch $GUI_CHECKED
    Case GUICtrlRead($OS)
        $strOS = True
        $strOSPlusApps = False
    Case GUICtrlRead($OSPlusApps)
        $strOS = False
        $strOSPlusApps = True
EndSwitch

Could you please post more of your code or pm it to me, if you don't want it to be made public?

Edited by saudumm

Share this post


Link to post
Share on other sites

thank you so much saudumm.. this really added the needed logic to my program. thanks again.

Share this post


Link to post
Share on other sites

thank you so much saudumm.. this really added the needed logic to my program. thanks again.

I'm glad I could help. :)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • byarotsky
      By byarotsky
      I am working on a script that pulls the current time from the internet and then reads contents from our backup server based on the month and week folders that are already created. This script will ultimate pass variables to another program that will restore the data from the respective folder to the computer that the script it running on. The script is built to find the 'windows' folders in the server structure which is \\server\serverfolder\01_16\3week
      \\server\serverfolder - is the server share
      01_16 - is month and year as to sort properly
      3week - is obviously the week
      Within the week folder there are user folders (eg. bsmith, jdoe, ganderson), in these folders are backups of full hard drives with include the windows folder which we are looking for.The script is running and is fully function the first time that it is run. I have also added a back button so if for some reason you are in the wrong list of folders you can navigate to the correct folder and then show the results again.
      The issue I am having is that I can show the contents and everything works well, unless I use the back button and navigate to a different set of folders (different week). The radio buttons do not respond properly. They will show both incorrect data and the count of radio buttons is not being updated.
      I have attempted to look for a solution and have tried many different ideas, but I just don't fully understand how a GUICtrlCreateRadio in a for loop with GUICtrlSetOnEvent should work.
       
      Any suggestions would be greatly appreciated. I apologize for the messy code.
      #include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GetTimeOnline ; Description ...: Retrieve the current date and time from TimeAPI.org. ; Syntax ........: _GetTimeOnline($iTimeZone) ; Parameters ....: $iTimeZone - An integer value of the timezone . ; 0 - UTC (Universal Time) ; 1 - EST (Eastern Time) ; 2 - CST (Central Time) ; 3 - MST (Mountain Time) ; 4 - PST (Pacific Time) ; 5 - AKST (Alaska Time) ; 6 - HAST (Hawaii-Aleutian Time) ; Return values .: Success: Returns the current Date and Time in the format YYYY/MM/DD HH:MM:SS ; Failure: Sets @error to non-zero and returns the same format as a successful return but using the system time. ; Author ........: guinness ; Link ..........: According to http://www.programmableweb.com/api/timeapi, this is for non-commercial use. ; Example .......: Yes ; =============================================================================================================================== Opt("GUIResizeMode", 1) Opt("GUIOnEventMode", 1) Global $vGUI_V = 450 Global $vGUI_ = 400 Local $ServerPath = "\\vault\backups\" Local $aFileList, $Current_Radio, $CurrentMonthFolder Local $Current_Gui = GUICreate("Test", 450, 400) Local $GuiBack = GUICtrlCreateButton("Back", 200, 250, 40, 40) GUICtrlCreateLabel("Please select the Windows folder to use", 20, 20) GUICtrlSetOnEvent($GuiBack, "BackPressed") GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") _GetTimeOnline(2) ;Central time zone _SelectFolder() While 1 Sleep(100) WEnd Exit Func _GetTimeOnline($iTimeZone) ; Retrieve the current time from TimeAPI.org. Ideal if your Windows clock is out of sync. Local $aTimeZone[7] = ['utc', 'est', 'cst', 'mst', 'pst', 'akst', 'hast'] Local $sRead = BinaryToString(InetRead('http://www.timeapi.org/' & $aTimeZone[$iTimeZone] & '/now?format=\Y/\m/\d%20/\H:\M:\S')) If @error Then SetError(1, 0, @YEAR & '/' & @MON & '/' & @MDAY & '/' & @HOUR & ':' & @MIN & ':' & @SEC) EndIf Local $aDays = StringSplit($sRead, "/") ; Split the string of days using the delimiter "," and the default flag value. ; For $i = 1 To $aDays[0] ; Loop through the array returned by StringSplit to display the individual values. ; MsgBox(4096, "", "$aDays[" & $i & "] - " & $aDays[$i]) ; Next $CurrentMonthFolder = $ServerPath & $aDays[2] & "_" & StringTrimLeft($aDays[1], 2) & "\" & Ceiling((@MDAY + (7 - @WDAY)) / 7) & "week" EndFunc ;==>_GetTimeOnline Func _SelectFolder() Local Const $sMessage = "Select users folder to restore data from:" ; Display an open dialog to select a file. Local $sFileSelectFolder = FileSelectFolder($sMessage, $CurrentMonthFolder) If @error Then ; Display the error message. ; MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.") Exit Else ; Display the selected folder. ; MsgBox($MB_SYSTEMMODAL, "", "You chose the following folder:" & @CRLF & $sFileSelectFolder) $aFileList = _FileListToArrayRec($sFileSelectFolder, "Windows", 14, -3, $FLTAR_SORT) If @error = 1 Then MsgBox($MB_SYSTEMMODAL, "", "Path was invalid or Windows folder not found.") _SelectFolder() EndIf If @error = 9 Then MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.") _SelectFolder() EndIf EndIf $CurrentMonthFolder = $sFileSelectFolder _ShowGui() EndFunc ;==>_SelectFolder Func _ShowGui() Local $startline = 20 If @error Then MsgBox(4096, "ERROR", "Error occured, no INI or incorrect Sections") Else For $i = 1 To $aFileList[0] $Current_Radiou = GUICtrlCreateRadio($aFileList[$i], 25, $startline + 20 * $i, 400) GUICtrlSetOnEvent(-1, "myEvent") ; This will tell us which radio was clicked Next EndIf GUISetState(@SW_SHOW, $Current_Gui) EndFunc ;==>_ShowGui Func BackPressed() ; MsgBox($MB_SYSTEMMODAL, "Go Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle) GUISetState(@SW_HIDE, $Current_Gui) _SelectFolder() EndFunc ;==>BackPressed Func myEvent() For $x = 1 To $aFileList[0] + 6 ; this is broken If GUICtrlRead($x) = 1 Then MsgBox(0, GUICtrlRead($x), GUICtrlRead($x, 1)) ;this is the path to the profile Next EndFunc ;==>myEvent Func SpecialEvents() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE ; MsgBox($MB_SYSTEMMODAL, "Close Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle) Exit Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE ; MsgBox($MB_SYSTEMMODAL, "Window Minimized", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle) Case @GUI_CtrlId = $GUI_EVENT_RESTORE ; MsgBox($MB_SYSTEMMODAL, "Window Restored", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle) EndSelect EndFunc ;==>SpecialEvents