Sign in to follow this  
Followers 0
LisHawj

Reading radio button selection

3 posts in this topic

Hi everyone,

I wrote the script below to map different network resources to drive letter Z (depending on the radio button selection from main script).  While it seems to work I don't believe it is the best practice or scripting logic.  I have 6 network resources that our users can map and can access only one at any given time (per policy).  The user is presented with 6 radio button respective of the network resource to map to drive Z.  Please review my script below and provide additional help, suggestions and feedbacks.  I am hoping to become more proficient as I continue to write basic tasks scripts with AutoIT.  I know I have much more to learn, and I respect your time in reviewing the script.  Thank you in advance for your time and consideration.

 

Func MapESD()
    $sMap = "Z:"

    ;Checks to see if Z: is currently map, if Yes, then disconnect the current Z: drive mapping
    If FileExists($sMap) Then
        DriveMapDel($sMap)
    EndIf

    ;Check to see which server is selected from options available to be utilize for new Z: drive mapping
    $Serv1 = GUICtrlRead($Radio7)
    $Serv2 = GUICtrlRead($Radio8)
    $Serv3 = GUICtrlRead($Radio9)
    $Serv4 = GUICtrlRead($Radio10)
    $Serv5 = GUICtrlRead($Radio11)
    $Serv6 = GUICtrlRead($Radio12)

    If $Serv1 = $GUI_CHECKED Then
        DriveMapAdd($sMap, "\\domain.com\folder", "domain\" & $Username & $Password)
    ElseIf $Serv2 = $GUI_CHECKED Then
        DriveMapAdd($sMap, "\\domain.com\folder", "domain\" & $Username & $Password)
    Else
        If $Serv3 = $GUI_CHECKED Then
            DriveMapAdd($sMap, "\\domain.com\folder", "domain\" & $Username & $Password)
        EndIf
    EndIf

    If $Serv4 = $GUI_CHECKED Then
        DriveMapAdd($sMap, "\\domain.com\folder", "domain\" & $Username & $Password)
    ElseIf $Serv5 = $GUI_CHECKED Then
        DriveMapAdd($sMap, "\\domain.com\folder", "domain\" & $Username & $Password)
    Else
        If $Serv6 = $GUI_CHECKED Then
            DriveMapAdd($sMap, "\\domain.com\folder", "domain\" & $Username & $Password)
        EndIf
    EndIf

    $Get_Map = DriveMapGet("Z:")
    $Verify_ESD = "Z:\ESD"

    If FileExists($Verify_ESD) Then
        $Terminal_Data = GUICtrlRead($Terminal) & @CRLF
        $Header1 = ("Result for network drive mapping:")
        GUICtrlSetData($Terminal, $Terminal_Data & $Header1 & @CRLF & $Get_Map & @CRLF)
        MsgBox(0, "", "Z:\ drive is connected successfully to: " & $Get_Map)
    Else
        $Terminal_Data = GUICtrlRead($Terminal) & @CRLF
        $Header1 = ("Result for network drive mapping:")
        GUICtrlSetData($Terminal, $Terminal_Data & $Header1 & @CRLF & $Get_Map & @CRLF)
        $Button_Clicked = MsgBox(6, "", "The network drive Z:\ is not found or is unreachable.  Please verify network connectivity and click TRY AGAIN, or click CONTINUE to proceed without mapping the Z:\ drive.")
        If $Button_Clicked = 2 Then
            MsgBox(0, "", "You clicked on CANCEL"); debug msgbox
            Exit
        ElseIf $Button_Clicked = 10 Then
            MsgBox(0, "", "You clicked Try Again"); debug msgbox
            Call("")
        Else
            MsgBox(0, "", "You clicked CONTINUE"); debug msgbox
            Call("")
        EndIf
    EndIf
EndFunc   ;==>MapESD

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I think using a ComboBox is better. Something similar to:

#cs -----------------------------------------------------------------------------------------------------------

    AutoIt Version: 3.3.6.1
    Author:                        AutoBert:    http://autoit.de/index.php?page=Thread&postID=164341#post164341

    Skriptbeispiel für den Umgang mit INI-Files und ComboBox
#ce -----------------------------------------------------------------------------------------------------------

#include <GUIConstantsEx.au3>
#Include <GuiComboBox.au3>
#include <StaticConstants.au3>

Const $sElect = "bitte eine URL auswählen"
Const $sAppIni=@AppDataDir&"\URL.INI"
Global $URL

If Not FileExists($sAppIni) Then
    $sData = "AutoIt=http://autoit.de" & @LF
    $sData &= "Buch=http://autoit.de/index.php?page=Thread&postID=92818#post92818" & @LF
    $sData &= "richtig Posten=http://autoit.de/index.php?page=Thread&threadID=4424" & @LF
    $sData &= "Tutorial=http://wiki.autoit.de/wiki/index.php/Tutorial" & @LF
    $sData &= "Skriptfehler finden=http://autoit.de/index.php?page=Thread&threadID=13785" & @LF
    $sData &= "Hilfe=http://translation.autoit.de/autoitinfo/hilfedateien/AutoIt-Hilfe-Deutsch-3.3.6.1-Stand-09_05_10.zip" & @LF
    $sData &= "MiniUrl-Manger=http://autoit.de/index.php?page=Thread&postID=164341#post164341" & @LF
    IniWriteSection($sAppIni, "URLs", $sData)
EndIf

$hGui = GUICreate("MiniUrl-Manager", 300, 90, 302, 218)
$hcboProg = GUICtrlCreateCombo("", 8, 8, 200, 25)
$hbtnAdd = GUICtrlCreateButton("&Hinzufügen", 213, 8,80)
$hbtnDel = GUICtrlCreateButton("&Löschen", 213, 35,80)
$hlblURL = GUICtrlCreateLabel("", 8, 70, 290,25)
$hbtnOpen = GUICtrlCreateButton("&Öffnen", 8, 35,200)
GUICtrlSetState($hbtnOpen, $GUI_DISABLE)
GUICtrlCreateGraphic(0,65,300,2,$SS_ETCHEDHORZ )
read_INI()
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hbtnAdd
            $write1 = InputBox("URL", "Bitte eine gültige URL eingeben")
            If $write1 <> "" Then
                $write2 = InputBox("URL verwalten  unter", "Bitte Kurzbegriff eingeben")
                If $write2 <> "" Then IniWrite($sAppIni, "URLs", $write2, $write1)
                GUICtrlSetData($hcboProg, $write2, $write2)
            EndIf
            show_Selection()
        Case $hbtnDel
            $sDel = GUICtrlRead($hcboProg)
            IniDelete($sAppIni, "URLs", $sDel)
            GUICtrlSetData($hcboProg,"")
            read_INI()
        Case $hcboProg
            show_Selection()
        Case $hbtnOpen
            ShellExecute($URL)
            ;ConsoleWrite($URL & @CRLF)
    EndSwitch
WEnd

Func read_INI()
    $list1 = IniReadSection($sAppIni, "URLs")
    ConsoleWrite($list1 & @CRLF)
    if IsArray($list1) Then
        For $i = 1 To $list1[0][0]
            GUICtrlSetData($hcboProg, $list1[$i][0])
        Next
    EndIf
    _GUICtrlComboBox_InsertString ($hcboProg,$sElect,0)
    _GUICtrlComboBox_SetCurSel($hcboProg,0)
EndFunc   ;==>read_INI

Func show_Selection()
    If GUICtrlRead($hcboProg) = $sElect Then
        GUICtrlSetState($hbtnOpen, $GUI_DISABLE)
        GUICtrlSetData($hlblURL, "")
    Else
        GUICtrlSetState($hbtnOpen, $GUI_ENABLE)
        $Prog = GUICtrlRead($hcboProg)
        ConsoleWrite("ausgewählt: " & $Prog & @CRLF)
        $URL = IniRead($sAppIni, "URLs", $Prog, "")
        GUICtrlSetData($hlblURL, $URL)
    EndIf
EndFunc   ;==>show_Selection

would be the better solution.

Edited by AutoBert
1 person likes this

Share this post


Link to post
Share on other sites

Thanks, your example is a cleaner and nicer execution for choices and/or selections.  I am still very new to AutoIT and don't fully comprehend the usage of the combo box yet.  I reviewed your example and I don't believe I have enough scripting knowledge to use it effectively.  Nonetheless, I am going to read up some more on the combo box and see where it takes me.  I welcome any additional inputs, feedbacks, and guidance.  Thanks!

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