williamk Posted June 29, 2007 Share Posted June 29, 2007 Have a function in a script that allows a user to change the date used in the main script (the variable $dtbefore). Problem is that if a user enters a bad date or non date characters the main script will not work. I tried to add some constraints by using the _DateisValid function and that works to a degree. However, the way I have it now the users input is split into an array and spit back out in a format the _DateisValid function can verify. If a user enters rubbish into the input I either get an error about the array being invalid or the script simply does not work correctly. The only way I can think of to fix this is to have three inputs, one for month, one for day, and one for year, and then put contraints on those as needed. I have some other scripts I need to write that use dates, so am wondering if there is an easy way to do this. Here is the datechange function of my script. expandcollapse popupFunc _ChangeDate() msgbox (0, "","This is the change date function") GUICreate("Change Date", 400, 140) $cdate = GUICtrlCreateInput("", 220, 5, 75, 20) GUICtrlSetState(-1, $GUI_NODROPACCEPTED) GUICtrlSetLimit(-1, 10) GUICtrlCreateLabel ( "Enter the date for pdf files you wish to copy", 10, 5) GUICtrlCreateLabel ( "MM/DD/YYYY", 220, 25) $btn = GUICtrlCreateButton("Continue", 200, 100, 60, 20) $btn2 = GUICtrlCreateButton("Exit", 130, 100, 60, 20) GUISetState() $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $btn2 Exit Case $msg = $btn $dtbefore = GUICtrlRead($cdate) $chk = StringSplit ($dtbefore, '/', 1) $dtentrd = $chk[3] & "/" & $chk[1] & "/" & $chk[2] if _DateIsValid($dtentrd) Then msgbox (0, "Valid Date", $dtentrd) $dtbefore = $dtentrd GuiDelete() ExitLoop Else msgbox (0, "Invalid Date", "The date must be entered exactly in the MM/DD/YYYY format. Please try again") guidelete() _ChangeDate() endif ExitLoop EndSelect Wend EndFunc Link to comment Share on other sites More sharing options...
Gif Posted June 29, 2007 Share Posted June 29, 2007 Have a function in a script that allows a user to change the date used in the main script (the variable $dtbefore). Problem is that if a user enters a bad date or non date characters the main script will not work. I tried to add some constraints by using the _DateisValid function and that works to a degree. However, the way I have it now the users input is split into an array and spit back out in a format the _DateisValid function can verify. If a user enters rubbish into the input I either get an error about the array being invalid or the script simply does not work correctly. The only way I can think of to fix this is to have three inputs, one for month, one for day, and one for year, and then put contraints on those as needed. I have some other scripts I need to write that use dates, so am wondering if there is an easy way to do this. Here is the datechange function of my script. expandcollapse popupFunc _ChangeDate() msgbox (0, "","This is the change date function") GUICreate("Change Date", 400, 140) $cdate = GUICtrlCreateInput("", 220, 5, 75, 20) GUICtrlSetState(-1, $GUI_NODROPACCEPTED) GUICtrlSetLimit(-1, 10) GUICtrlCreateLabel ( "Enter the date for pdf files you wish to copy", 10, 5) GUICtrlCreateLabel ( "MM/DD/YYYY", 220, 25) $btn = GUICtrlCreateButton("Continue", 200, 100, 60, 20) $btn2 = GUICtrlCreateButton("Exit", 130, 100, 60, 20) GUISetState() $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $btn2 Exit Case $msg = $btn $dtbefore = GUICtrlRead($cdate) $chk = StringSplit ($dtbefore, '/', 1) $dtentrd = $chk[3] & "/" & $chk[1] & "/" & $chk[2] if _DateIsValid($dtentrd) Then msgbox (0, "Valid Date", $dtentrd) $dtbefore = $dtentrd GuiDelete() ExitLoop Else msgbox (0, "Invalid Date", "The date must be entered exactly in the MM/DD/YYYY format. Please try again") guidelete() _ChangeDate() endif ExitLoop EndSelect Wend EndFunc GUICtrlCreateDate() 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