Jump to content
Sign in to follow this  
Zlow

GUI input box and array resizing

Recommended Posts

Zlow

First post, but I hope I'm not beinga newb asking a question that was just answered. I've read the help and searched the forums but I cant find anything quite related to what I'm looking for.

I'm creating a scritp to help automate account creations through an AS400 terminal session.

I have a GUI window created that has two basic functions. The first asks for a path (with browse button) to an Excel file. The 2nd is for the user to input data into 4 required fields. When the create button is clicked the script looks to see if an excel file has been chosen, if so it opens the excel file, reads it into an array, then calls the functions to create the accounts. I have that part working beautifully. I'm running into a problem getting the user input data into the same array to be sent to the functions. The GUI has 3 rows, each with 4 cells.

$MimicID1=GuiCtrlCreateInput("",20,100,100,20)
$UserName1=GuiCtrlCreateInput("",130,100,100,20)
$EmpID1=GuiCtrlCreateInput("",240,100,100,20)
$AccountName1=GuiCtrlCreateInput("",350,100,100,20)
$MimicID2=GuiCtrlCreateInput("",20,122,100,20)
$UserName2=GuiCtrlCreateInput("",130,122,100,20)
$EmpID2=GuiCtrlCreateInput("",240,122,100,20)
$AccountName2=GuiCtrlCreateInput("",350,122,100,20)
$MimicID3=GuiCtrlCreateInput("",20,144,100,20)
$UserName3=GuiCtrlCreateInput("",130,144,100,20)
$EmpID3=GuiCtrlCreateInput("",240,144,100,20)
$AccountName3=GuiCtrlCreateInput("",350,144,100,20)

Below I'll post the function I'm working on to get the data out of these cells and into an array. The problem I have is the array not being the correct size. When the array data is generated by reading the Excel spredsheet the data starts at [1][1] rather than 0. I've designed the fuctions that actually create the account to expect this. Thus I need the array to be created from the user input data to start at [1][1] as well.

This is my latest failed attempt.

Func SetupArray()   ; Creates accounts by Excel File or GUI entry
    If $FoundExcel = 0 Then                     ; If Excel file has not been chosen
        DIM $value[5][6]
        $value[1][1] = GUICtrlRead($MimicID1)
        $value[1][2] = GUICtrlRead($UserName1)
        $value[1][3] = GUICtrlRead($EmpID1)
        $value[1][4] = GUICtrlRead($AccountName1)
        $value[1][5] = ""
        $value[2][1] = GUICtrlRead($MimicID1)
        $value[2][2] = GUICtrlRead($UserName1)
        $value[2][3] = GUICtrlRead($EmpID1)
        $value[2][4] = GUICtrlRead($AccountName1)
        $value[2][5] = ""
        $value[3][1] = GUICtrlRead($MimicID1)
        $value[3][2] = GUICtrlRead($UserName1)
        $value[3][3] = GUICtrlRead($EmpID1)
        $value[3][4] = GUICtrlRead($AccountName1)
        $value[3][5] = ""
        $value[4][1] = GUICtrlRead($MimicID1)
        $value[4][2] = GUICtrlRead($UserName1)
        $value[4][3] = GUICtrlRead($EmpID1)
        $value[4][4] = GUICtrlRead($AccountName1)
        $value[4][5] = ""
        $a=1
        $b=1
        While $value[$a][$b] <> "" AND $a<4
            While $value[$a][$b] <> ""
                ReDim $array[$array[0]+1]
                $array[$a][$b]=GUICtrlRead($value[$a][$b]
                MsgBox(0,"","Round " & $b)          ; Used for testing purposes to count
                $b+=1
            WEnd
            $a+=1
            $b=1
        WEnd
        CreateAccount()
        
    Else
        $oExcel = _ExcelBookOpen($ExcelLoc)     ; Open Excel File
        $array = _ExcelReadSheetToArray($oExcel, 1, 1)  ; Read Excel sheet into array
        _ExcelBookClose($oExcel)    ; Close Excel File
        CreateAccount()
    EndIf
EndFunc

I think I'm overcomplicating this problem but I've been working on this for off and on for 4 days now. I'm reaching the end of my rope, any help would be appreciated.

Thanks

Share this post


Link to post
Share on other sites
martin

First post, but I hope I'm not beinga newb asking a question that was just answered. I've read the help and searched the forums but I cant find anything quite related to what I'm looking for.

I'm creating a scritp to help automate account creations through an AS400 terminal session.

I have a GUI window created that has two basic functions. The first asks for a path (with browse button) to an Excel file. The 2nd is for the user to input data into 4 required fields. When the create button is clicked the script looks to see if an excel file has been chosen, if so it opens the excel file, reads it into an array, then calls the functions to create the accounts. I have that part working beautifully. I'm running into a problem getting the user input data into the same array to be sent to the functions. The GUI has 3 rows, each with 4 cells.

$MimicID1=GuiCtrlCreateInput("",20,100,100,20)
 $UserName1=GuiCtrlCreateInput("",130,100,100,20)
 $EmpID1=GuiCtrlCreateInput("",240,100,100,20)
 $AccountName1=GuiCtrlCreateInput("",350,100,100,20)
 $MimicID2=GuiCtrlCreateInput("",20,122,100,20)
 $UserName2=GuiCtrlCreateInput("",130,122,100,20)
 $EmpID2=GuiCtrlCreateInput("",240,122,100,20)
 $AccountName2=GuiCtrlCreateInput("",350,122,100,20)
 $MimicID3=GuiCtrlCreateInput("",20,144,100,20)
 $UserName3=GuiCtrlCreateInput("",130,144,100,20)
 $EmpID3=GuiCtrlCreateInput("",240,144,100,20)
 $AccountName3=GuiCtrlCreateInput("",350,144,100,20)

Below I'll post the function I'm working on to get the data out of these cells and into an array. The problem I have is the array not being the correct size. When the array data is generated by reading the Excel spredsheet the data starts at [1][1] rather than 0. I've designed the fuctions that actually create the account to expect this. Thus I need the array to be created from the user input data to start at [1][1] as well.

This is my latest failed attempt.

Func SetupArray()   ; Creates accounts by Excel File or GUI entry
     If $FoundExcel = 0 Then                       ; If Excel file has not been chosen
         DIM $value[5][6]
         $value[1][1] = GUICtrlRead($MimicID1)
         $value[1][2] = GUICtrlRead($UserName1)
         $value[1][3] = GUICtrlRead($EmpID1)
         $value[1][4] = GUICtrlRead($AccountName1)
         $value[1][5] = ""
         $value[2][1] = GUICtrlRead($MimicID1)
         $value[2][2] = GUICtrlRead($UserName1)
         $value[2][3] = GUICtrlRead($EmpID1)
         $value[2][4] = GUICtrlRead($AccountName1)
         $value[2][5] = ""
         $value[3][1] = GUICtrlRead($MimicID1)
         $value[3][2] = GUICtrlRead($UserName1)
         $value[3][3] = GUICtrlRead($EmpID1)
         $value[3][4] = GUICtrlRead($AccountName1)
         $value[3][5] = ""
         $value[4][1] = GUICtrlRead($MimicID1)
         $value[4][2] = GUICtrlRead($UserName1)
         $value[4][3] = GUICtrlRead($EmpID1)
         $value[4][4] = GUICtrlRead($AccountName1)
         $value[4][5] = ""
         $a=1
         $b=1
         While $value[$a][$b] <> "" AND $a<4
             While $value[$a][$b] <> ""
                 ReDim $array[$array[0]+1]
                 $array[$a][$b]=GUICtrlRead($value[$a][$b]
                 MsgBox(0,"","Round " & $b)        ; Used for testing purposes to count
                 $b+=1
             WEnd
             $a+=1
             $b=1
         WEnd
         CreateAccount()
         
     Else
         $oExcel = _ExcelBookOpen($ExcelLoc)    ; Open Excel File
         $array = _ExcelReadSheetToArray($oExcel, 1, 1)   ; Read Excel sheet into array
         _ExcelBookClose($oExcel)   ; Close Excel File
         CreateAccount()
     EndIf
 EndFunc

I think I'm overcomplicating this problem but I've been working on this for off and on for 4 days now. I'm reaching the end of my rope, any help would be appreciated.

Thanks

I think we need more information. I don't see how to know what $array is, how it is first declared and what th e value of $array[0] is set to.

But since you say

ReDim $array[$array[0]+1]

but never change the value of $array[0] the arra will not grow. I suspect you really should be using

Redim $array[Ubound($array) + 1)

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Zlow

I think we need more information. I don't see how to know what $array is, how it is first declared and what th e value of $array[0] is set to.

But since you say

ReDim $array[$array[0]+1]

but never change the value of $array[0] the arra will not grow. I suspect you really should be using

Redim $array[Ubound($array) + 1)

I didn't include where I defined the array size because it shouldn't matter. The first thing I do is read if the input box is empty, if not I set the array size the copy the data to the cell. Your suspicion was right on. I knew the array was not being sized properly but coudln't figure out the syntax.

While $value[$a][$b] <> "" AND $a<4
            While $value[$a][$b] <> ""
                ReDim $array[$a+1][5]
                $array[$a][$b]=$value[$a][$b]
;~              MsgBox(0,"","Round " & $a & " " & $b & " " & $array[$a][$b])
                $b+=1
            WEnd
            $a+=1
            $b=1
        WEnd

That is the working code.

If anyone has a smarter way of getting this done please let me know. I tried several ways but my knowlege of Autoit is just begining. I've never programed before and I'm on day 6 trying to learn this in my spare time.

Thanks for your help!

Share this post


Link to post
Share on other sites
martin

While $value[$a][$b] <> "" AND $a<4
             While $value[$a][$b] <> ""
                 ReDim $array[$a+1][5]
                 $array[$a][$b]=$value[$a][$b]
;~               MsgBox(0,"","Round " & $a & " " & $b & " " & $array[$a][$b])
                 $b+=1
             WEnd
             $a+=1
             $b=1
         WEnd
I still can't be sure what you want to do from what you've posted, but in that last part you redim the array inside a while loop according to the value of $a, but $a doesn't change inside that loop, so it would be better to have the Redim outside so you aren't needlessly repeating code which has no effect like this

        While $value[$a][$b] <> "" AND $a<4
               ReDim $array[$a+1][5]
                While $value[$a][$b] <> ""
                 $array[$a][$b]=$value[$a][$b]
;~               MsgBox(0,"","Round " & $a & " " & $b & " " & $array[$a][$b])
                 $b+=1
                if $b > 4 then exitloop;this extra line is advisable
             WEnd
             $a+=1
             $b=1
         WEnd

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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  

×