Jump to content

Radio Button and Checkbox dependent


Recommended Posts


Trying to adjust my code but I have hit a wall. The code creates a directory with subfolders based on users input. However some projects require a PDF to be put in to the folder structure. I tried to just put a checkbox in and if true it would just copy the pdf to the folder. I however have been unsuccessful in making this happen. Any help would be great.

#include <GUIConstantsEx.au3>
#include <GUIComboBox.au3>
#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>


$hGUI = GUICreate("Program", 480, 397, 102, 94)
$Pic1 = GUICtrlCreatePic("\\Server_Location\Image.jpg", 52, 8, 377, 129, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
GUISetFont(8, 400, 0, "Century Gothic")
GUISetBkColor(0xFFFFFF)   ; set color to white
Global $ProjectNumberLabel = GUICtrlCreateLabel("*Project Number:", 260, 230, 90, 20);ADDED THIS
Global $ProjectNumber = GUICtrlCreateInput("", 350, 230, 120, 20);ADDED THIS
GUICtrlSetLimit($projectNumber, 11);ADDED THIS
Global $ProjectName = GUICtrlCreateInput("", 350, 260, 120, 20) ;ADDED THIS
GUICtrlSetLimit($projectname, 20)
Global $ProjectNameLabel = GUICtrlCreateLabel("*Project Name:", 260, 260, 90, 20);ADDED THIS
Global $OkButton = GUICtrlCreateButton("OK", 80, 333, 75, 25)
Global $Radio2 = GUICtrlCreateRadio("Charlie", 40, 280, 113, 17)
Global $Radio3 = GUICtrlCreateRadio("Bravo", 40, 250, 113, 17)
Global $Radio1 = GUICtrlCreateRadio("Alpha", 40, 220, 113, 17) ; left/right,up/down,width,height
GUICtrlSetState(-1, $GUI_CHECKED)
Global $CancelButton = GUICtrlCreateButton("Cancel", 209, 333, 75, 25)
Global $SelectOfficeLabel = GUICtrlCreateLabel("*Which office:", 260, 200, 80, 20);ADDED THIS
####################################################
$Group1 = GUICtrlCreateGroup("What kind of Directory is this project for?", 20, 200, 218, 110)
Global $Checkbox1 = GUICtrlCreateCheckbox("PDF Copy to folder", 40, 170, 170, 20)
####################################################
$MenuItem2 = GUICtrlCreateMenu("&File")
$Close = GUICtrlCreateMenuItem("Close", $MenuItem2)
$MenuItem1 = GUICtrlCreateMenu("&Folder Structure")
$DesignMenu = GUICtrlCreateMenuItem("Alpha", $MenuItem1)
$FRBEMenu = GUICtrlCreateMenuItem("Bravo", $MenuItem1)
$StudiesMenu = GUICtrlCreateMenuItem("Charlie", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenu("&Help")
$FAQ = GUICtrlCreateMenuItem("FAQ", $MenuItem3)
$AboutMenu = GUICtrlCreateMenuItem("About", $MenuItem3)
Global $DisclaimerLabel = GUICtrlCreateLabel("* - Required Fields.", 320, 300, 110, 20);ADDED THIS

$hCombo = GUICtrlCreateCombo("", 350, 200, 120, 21) ; x, up or down, width of field, x
GUICtrlSetData($hCombo, "OfficeLocation1|OfficeLocation2|OfficeLocation3|OfficeLocation4", 'Please Select an Office')

GUISetState()

$sCurrCombo = ""

While (1)
    Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
            Exit

Case $AboutMenu
            Msgbox ($MB_ICONINFORMATION, 'About', "This is a Directory Creator" _
            & @CRLF & "" _
            & @CRLF & "If you have any issues please put in a service desk ticket" _
            & @CRLF & "" _
            & @CRLF & "Version 12.5" _
            & @CRLF & "Build - 11.25.2024" _
            & @CRLF & "" _
            & @CRLF & "Latest Author: Admin")

case $FAQ
            Msgbox ($MB_ICONINFORMATION,'FAQ', "Q-Example question here?" & @CRLF & "A- Example answer here")

Case $cancelbutton
            Exit
                            
Case $Close
            Exit
            
Case $Radio1
   If GUICtrlRead($Radio1, $GUI_Checked) Then _UNChecked_ALL()
    
Case $OkButton

            $DatafromUser = StringLeft(GUICtrlRead($ProjectNumber),2) & "-" & StringMid (GUICtrlRead($ProjectNumber),3,6) & "-" & StringRight(GUICtrlRead($ProjectNumber),2)
            If GUICtrlRead($ProjectNumber) = "" Then IsEmptyProjectNumber ()
            $DatafromUser1 = StringReplace(GUICtrlRead($ProjectName)," ", "_",0)
            If GUICtrlRead($ProjectName) = "" Then IsEmptyProjectName ()
            $DatafromUserFinal =$DatafromUser & "-" & $DatafromUser1
            
If GUICtrlRead($hcombo) = "Office Location 1" Then
      Local $Server = "\\serverlocation\OfficeLocation1\"
        If GUICtrlRead($Radio2) = "1" Then Remote_CreateOfficeCharlieDirectory()
        If GUICtrlRead($Radio3) = "1" Then Remote_CreateOfficeBravoDirectory()
        EndIf

If GUICtrlRead($hcombo) = "Office Location 2" Then
      Local $Server = "\\serverlocation\OfficeLocation2\"
        If GUICtrlRead($Radio2) = "1" Then Remote_CreateOfficeCharlieDirectory()
        If GUICtrlRead($Radio3) = "1" Then Remote_CreateOfficeBravoDirectory()
        EndIf

If GUICtrlRead($hcombo) = "Office Location 3" Then
       Local $Server = "\\serverlocation\OfficeLocation3\"
        If GUICtrlRead($Radio2) = "1" Then Remote_CreateOfficeCharlieDirectory()
        If GUICtrlRead($Radio3) = "1" Then Remote_CreateOfficeBravoDirectory()
        EndIf

If GUICtrlRead($hcombo) = "Office Location 4" Then
        Local $Server = "\\serverlocation\OfficeLocation4\"
        If GUICtrlRead($Radio2) = "1" Then Remote_CreateOfficeCharlieDirectory()
        If GUICtrlRead($Radio3) = "1" Then Remote_CreateOfficeBravoDirectory()
        EndIf

; If combo opened reset flag to allow for selection of same item
    If _GUICtrlComboBox_GetDroppedState($hCombo) Then $sCurrCombo = ""
EndSwitch
WEnd

;Special Func for XX office. Shared folder acting as a server for remote office
Func Remote_CreateAlphaDirectory()
    DirCreate($Server & $DatafromUserFinal & '\A')
DirCreate($Server & $DatafromUserFinal & '\A\B')
DirCreate($Server & $DatafromUserFinal & '\B')
DirCreate($Server & $DatafromUserFinal & '\B\1')
DirCreate($Server & $DatafromUserFinal & '\C')
    Exit
EndFunc

;Special Func for XX office. 
Func Remote_CreateOfficeBravoDirectory()
DirCreate($Server & $DatafromUserFinal & '\A')
DirCreate($Server & $DatafromUserFinal & '\A\B')
DirCreate($Server & $DatafromUserFinal & '\B')
DirCreate($Server & $DatafromUserFinal & '\B\1')
DirCreate($Server & $DatafromUserFinal & '\C')
Exit
EndFunc

Func Remote_CreateOfficeCharlieDirectory()
DirCreate($Server & $DatafromUserFinal & '\A')
DirCreate($Server & $DatafromUserFinal & '\A\B')
DirCreate($Server & $DatafromUserFinal & '\B')
DirCreate($Server & $DatafromUserFinal & '\B\1')
DirCreate($Server & $DatafromUserFinal & '\C')
FileCopy ($Server & '\FileName.pdf', $Server & $DatafromUserFinal & '\Agreements')
    Exit
EndFunc


Func IsEmptyProjectNumber ()
    If GUICtrlRead($ProjectNumber) = "" Then MsgBox($MB_SYSTEMMODAL, "Error", "Project Number Missing", 10)
EndFunc   ;==>Checks if ProjectNumber Dialog box is empty

Func IsEmptyProjectName ()
    If GUICtrlRead($ProjectName) = "" Then MsgBox($MB_SYSTEMMODAL, "Error", "Project Name Missing", 10)
EndFunc   ;==>Checks if ProjectName Dialog box is empty
Exit

GUI2.JPG

GUI.JPG

Edited by Melba23
Added code tags
Link to comment
Share on other sites

While (1)
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            
        ; ...
        ; ...
        ; ...
        ; ...

        Case $OkButton
            Local $ProjNum = GUICtrlRead($ProjectNumber)
            $DatafromUser = StringLeft($ProjNum, 2) & "-" & StringMid($ProjNum, 3, 6) & "-" & StringRight($ProjNum, 2)
            If $ProjNum = "" Then IsEmptyProjectNumber()
            $DatafromUser1 = StringReplace(GUICtrlRead($ProjectName), " ", "_", 0)
            If GUICtrlRead($ProjectName) = "" Then IsEmptyProjectName()
            $DatafromUserFinal = $DatafromUser & "-" & $DatafromUser1

            Local $Server, $sLocation = GUICtrlRead($hCombo)
            Switch $sLocation
                Case "Office Location 1"
                    $Server = "\\serverlocation\OfficeLocation1\"
                    If GUICtrlRead($Radio2) = "1" Then Remote_CreateOfficeCharlieDirectory()
                    If GUICtrlRead($Radio3) = "1" Then Remote_CreateOfficeBravoDirectory()

                Case "Office Location 2"
                    $Server = "\\serverlocation\OfficeLocation2\"
                    If GUICtrlRead($Radio2) = "1" Then Remote_CreateOfficeCharlieDirectory()
                    If GUICtrlRead($Radio3) = "1" Then Remote_CreateOfficeBravoDirectory()

                Case "Office Location 3"
                    $Server = "\\serverlocation\OfficeLocation3\"
                    If GUICtrlRead($Radio2) = "1" Then Remote_CreateOfficeCharlieDirectory()
                    If GUICtrlRead($Radio3) = "1" Then Remote_CreateOfficeBravoDirectory()

                Case "Office Location 4"
                    $Server = "\\serverlocation\OfficeLocation4\"
                    If GUICtrlRead($Radio2) = "1" Then Remote_CreateOfficeCharlieDirectory()
                    If GUICtrlRead($Radio3) = "1" Then Remote_CreateOfficeBravoDirectory()

            EndSwitch
            
            ; If combo opened reset flag to allow for selection of same item
            If _GUICtrlComboBox_GetDroppedState($hCombo) Then $sCurrCombo = ""

    EndSwitch
WEnd


Func Remote_CreateOfficeCharlieDirectory()
    DirCreate($Server & $DatafromUserFinal & '\A')
    DirCreate($Server & $DatafromUserFinal & '\A\B')
    DirCreate($Server & $DatafromUserFinal & '\B')
    DirCreate($Server & $DatafromUserFinal & '\B\1')
    DirCreate($Server & $DatafromUserFinal & '\C')
    If GUICtrlRead($Checkbox1) = 1 Then FileCopy($Server & '\FileName.pdf', $Server & $DatafromUserFinal & '\Agreements')
    Exit
EndFunc   ;==>Remote_CreateOfficeCharlieDirectory

I added a couple more touches.

Edit:
so that it doesn't have to read the same data  GUICtrlRead($hCombo) or GUICtrlRead($ProjectNumber) 4,5 times if it has already read it once

Edited by ioa747

I know that I know nothing

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...