Jump to content

GUI Not Working on 2nd Run


Recommended Posts

Guys,

     Just  a quick question. When I run this the first time, it works like it suppose to. The issue is when I want to see another set of dates on a second run, I get an Array error 

"Array variable has incorrect number of subscripts or subscript dimension range exceeded"

 

Do I need to do an Array delete function to get it to work  to run multiple times?

 

#include <Array.au3>
#include <String.au3>
#include <ButtonConstants.au3>
#include <DateTimeConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>


#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("Form1", 863, 645, 192, 123)
$Tab1 = GUICtrlCreateTab(8, 8, 841, 553, $TCS_FIXEDWIDTH)
$Main = GUICtrlCreateTabItem("Main")
$Date1 = GUICtrlCreateMonthCal(@YEAR &'/'&@MON &'/'& @MDAY, 142, 157, 249, 185)
$Date2 = GUICtrlCreateMonthCal(@YEAR &'/'&@MON &'/'& @MDAY, 478, 157, 257, 185)
$Label1 = GUICtrlCreateLabel("Start Date", 227, 125, 83, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("End Date", 563, 125, 82, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$go = GUICtrlCreateButton("Run", 568, 382, 99, 33)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$stop = GUICtrlCreateButton("Stop and Exit", 216, 382, 99, 33)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
GUICtrlCreateTabItem("")
$Progress1 = GUICtrlCreateProgress(8, 608, 390, 25)
$Progress2 = GUICtrlCreateProgress(430, 609, 390, 25)
$Label5 = GUICtrlCreateLabel("Main Progress", 8, 584, 74, 17)
$Label6 = GUICtrlCreateLabel("Current Process Progress", 429, 589, 123, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $stop
            Exit
        Case $go

            $Date1 = GUICtrlRead($Date1)
            $Date2 = GUICtrlRead($Date2)
            ;GuiDelete($Form1)

            $Date1 = StringSplit($Date1,'/',2)
            $Date2 = StringSplit($Date2,'/',2)

            MsgBox(0,'Date',$Date1[0] & '/' & $Date1[1] & '/' & $Date1[2] & ' - ' & $Date2[0] & '/' & $Date2[1] & '/' & $Date2[2])


    EndSwitch
WEnd

 

Link to comment
Share on other sites

Try this code:

#include <Array.au3>
#include <String.au3>
#include <ButtonConstants.au3>
#include <DateTimeConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>


#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("Form1", 863, 645, 192, 123)
$Tab1 = GUICtrlCreateTab(8, 8, 841, 553, $TCS_FIXEDWIDTH)
$Main = GUICtrlCreateTabItem("Main")
$idDate1 = GUICtrlCreateMonthCal(@YEAR &'/'&@MON &'/'& @MDAY, 142, 157, 249, 185)
$idDate2 = GUICtrlCreateMonthCal(@YEAR &'/'&@MON &'/'& @MDAY, 478, 157, 257, 185)
$Label1 = GUICtrlCreateLabel("Start Date", 227, 125, 83, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("End Date", 563, 125, 82, 28)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$go = GUICtrlCreateButton("Run", 568, 382, 99, 33)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$stop = GUICtrlCreateButton("Stop and Exit", 216, 382, 99, 33)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
GUICtrlCreateTabItem("")
$Progress1 = GUICtrlCreateProgress(8, 608, 390, 25)
$Progress2 = GUICtrlCreateProgress(430, 609, 390, 25)
$Label5 = GUICtrlCreateLabel("Main Progress", 8, 584, 74, 17)
$Label6 = GUICtrlCreateLabel("Current Process Progress", 429, 589, 123, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $stop
            Exit
        Case $go

            $Date1 = GUICtrlRead($idDate1)
            $Date2 = GUICtrlRead($idDate2)
            ;GuiDelete($Form1)

            $Date1 = StringSplit($Date1,'/',2)
            $Date2 = StringSplit($Date2,'/',2)

            MsgBox(0,'Date',$Date1[0] & '/' & $Date1[1] & '/' & $Date1[2] & ' - ' & $Date2[0] & '/' & $Date2[1] & '/' & $Date2[2])


    EndSwitch
WEnd

You were using the same variable for the StringSplit string and the Date Control ID, The Date control ID would be overwritten when StringSplit is called... in the 2nd run GUICtrlRead cannot read the Date control because there is no control ID in $Date1 and $Date2.

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

@TheDcoder Thank you so much for replying to my question. I apologize for it taking so long for me replying back. Ended up having to take an unexpected trip out of town and then got covered up with work. I tried your suggestion and it works perfect. Once again, thank you for chiming in and helping!!! 

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...