Jump to content

Storing a function call in an array element?


Recommended Posts

I'm attempting to create a menu driven software install screen. I'm sure it's been done countless times and lots of questions asked, but I would like to do it this way, to attempt to give myself a better understanding of the language.

What i've done is store checkboxes in 1 array column, the checked/unchecked state in another, and I'd like to put the function call to that software install in the 3rd column. That way, when the install button is clicked, it checks the state of the checkboxes, then will run the programs associated with those clicked checkboxes, hence why I wanted to put the function calls in the 3rd column of the array.

When I attempt to assign the function call to an array element and run the program, it starts to auto-install the programs instead. I have made the software install scripts as functions and included them appropriately, I believe. Here is my code and thanks for the review!

#include "matlab_func.au3"
#include "visio2003_func.au3"
#include <GuiConstants.au3>
#include <Array.au3>

Dim $array[5][3] ;


GuiCreate("Test Case")

$group1 = GUICtrlCreateGroup("Testing 1", 15, 30, 120, 100)
$button1 = GUICtrlCreateButton("Install", 20, 150, 50,20)
$button2 = GUICtrlCreateButton("Done!", 20, 170, 50,20)
GUIStartGroup()
$array[0][0] = GUICtrlCreateCheckbox("Matlab", 25, 50, 100, 20)
$array[1][0] = GUICtrlCreateCheckbox("Visio", 25, 70, 100, 20)
$array[2][0] = GUICtrlCreateCheckbox("Project", 25, 90, 100, 20)
$array[3][0] = GUICtrlCreateCheckbox("StarTeam", 25, 110, 100, 20)

;$array[0][2] = matlab()
;$array[1][2] = visio2003()
GUISetState()

While 1
    $msg = GUIGetMsg()

    if $msg = $button1 Then
        for $i = 0 To 1 Step 1
            if BitAnd(GUICtrlRead($array[$i][0]), $GUI_CHECKED) Then
                $array[$i][1] = 1
            EndIf
        Next
        for $j = 0 to 1 Step 1
            if $array[$j][1] > 0 Then
                Run($array[$j][2])
            EndIf
        Next
        
    EndIf


    If $msg = $GUI_EVENT_CLOSE or $msg = $button2 Then ExitLoop
Wend
Link to comment
Share on other sites

You could try initializing your [$var][1] element to 0 at the start of your script. I'm not sure if AutoIt pre-initializes its variables to zero or null/empty, but it's always good practice to initialize your declared variables.

Also, is it intentional that your For..Next loops only go through the first two elements of the array?

Edited by omikron48
Link to comment
Share on other sites

When you do:

$array[0][2] = matlab()

You are actually running matlab() and storing it's return value.

You should instead store the funciton name as a string

$array[0][2] = "matlab"

And then Call() it. Run() does something entirely else, see the helpfile.

Edited by AdmiralAlkex
Link to comment
Share on other sites

@Omikron: Yes I knew it only went through the first two elements. I was still in the experimentation stage and those two were the only ones I had done at this time.

@Admiral: Doh! I should have known that is what I was doing. That's what I do in C++, so naturally that's what would happen here...

Being new to AutoIT, I did not know about the Call() function. Thanks for the information!

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