Jump to content

Require input field base upon another input field


Recommended Posts

I have a gui with several input boxes. I have a If statement making the first 2 inputs required. How do I make is so that if someone types something in the input control $CollectEpisodeNumber, then the script will not continue unless something is also in the input control, $CollectEpisodeSeason. I will post the code I have.

;Create GUI
    $Main = GUICreate('Newzbin Auto Downloader', 300, 150)
    Opt("GUICoordMode",1)
    $CollectName = GUICtrlCreateInput('',100,10,150)
    $NameLabel = GUICtrlCreateLabel('Name of Item',15,13)
    $CollectCategory = GUICtrlCreateCombo('',100,35,60,$CBS_UPPERCASE,$CBS_DROPDOWNLIST)
    GUICtrlSetData(-1,"Unknown|Anime|Apps|Books|Consoles|Emulation|Games|Misc|Movies|Music|PDA|TV")
    $CategoryLabel = GUICtrlCreateLabel('Category',15,38)
    $CollectEpisodeSeason = GUICtrlCreateInput('',100,60,50)
    $EpisodeSeasonLabel = GUICtrlCreateLabel('Episode Season',15,63)
    $CollectEpisodeNumber = GUICtrlCreateInput('',100,85,50)
    $EpisodeLabelLabel = GUICtrlCreateLabel('Episode Number',15,88)
    $CollectMaxItems = GUICtrlCreateInput('',100,110,50)    
    $MaxItemsLabel = GUICtrlCreateLabel('Max # of Items',15,112)

GUISetState ()
    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit
            Case $msg = $Button_1
                GLOBAL $Name = GUICtrlRead($CollectName)
                GLOBAL $Category = GUICtrlRead($CollectCategory)
                GLOBAL $MaxItems = GUICtrlRead($CollectMaxItems)
                GLOBAL $EpisodeSeason = GUICtrlRead($CollectEpisodeSeason)
                GLOBAL $EpisodeNumber = GUICtrlRead($CollectEpisodeNumber)
                If $Name == '' OR $Category =='' Then
                    MsgBox(0,'Name','Both name and category are required!')
                Else
                WinSetState('Newzbin Auto Downloader','',@SW_HIDE)
                ExitLoop
                EndIf
            Case $msg = $Button_2
                Exit
        EndSelect
    Wend
Link to comment
Share on other sites

try:

#include <GuiConstants.au3>
Opt("GUICoordMode", 1)

$Main = GUICreate('Newzbin Auto Downloader', 300, 150)
$CollectName = GUICtrlCreateInput('', 100, 10, 150)
$NameLabel = GUICtrlCreateLabel('Name of Item', 15, 13)
$CollectCategory = GUICtrlCreateCombo('', 100, 35, 60, $CBS_UPPERCASE, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "Unknown|Anime|Apps|Books|Consoles|Emulation|Games|Misc|Movies|Music|PDA|TV")
$CategoryLabel = GUICtrlCreateLabel('Category', 15, 38)
$CollectEpisodeSeason = GUICtrlCreateInput('', 100, 60, 50)
$EpisodeSeasonLabel = GUICtrlCreateLabel('Episode Season', 15, 63)
$CollectEpisodeNumber = GUICtrlCreateInput('', 100, 85, 50)
$EpisodeLabelLabel = GUICtrlCreateLabel('Episode Number', 15, 88)
$CollectMaxItems = GUICtrlCreateInput('', 100, 110, 50)
$MaxItemsLabel = GUICtrlCreateLabel('Max # of Items', 15, 112)

GUISetState()
$rd = GUICtrlRead($CollectEpisodeNumber)
While 1
    If $rd <> GUICtrlRead($CollectEpisodeNumber) Then
        If GUICtrlRead($CollectEpisodeSeason) == '' Then
            GUICtrlSetData($CollectEpisodeNumber, $rd)
        EndIf
    EndIf
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $Button_1
            Global $Name = GUICtrlRead($CollectName)
            Global $Category = GUICtrlRead($CollectCategory)
            Global $MaxItems = GUICtrlRead($CollectMaxItems)
            Global $EpisodeSeason = GUICtrlRead($CollectEpisodeSeason)
            Global $EpisodeNumber = GUICtrlRead($CollectEpisodeNumber)
            If $Name == '' Or $Category == '' Then
                MsgBox(0, 'Name', 'Both name and category are required!')
            Else
                WinSetState('Newzbin Auto Downloader', '', @SW_HIDE)
                ExitLoop
            EndIf
        Case $msg = $Button_2
            Exit
    EndSelect
WEnd
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...