Sign in to follow this  
Followers 0
Toco1982

How to use "Function with Array parameter"

4 posts in this topic

Hello Community,

I use AutoIT quite a while now and somehow I seem to be mentally blocked :ermm:

I am facing the following problem:

I have 2 script files:

  • test1
  • test2
Test2 contains the function definition as follows:

"Func PaketInstaller($InstSprache, $LogFileHandle, $Software, $Pfad, $WinVersion, $Architektur)"

  • $InstSprache, $Pfad, $WinVersion, $Architektur= String
  • $LogFileHandle = Handle to a txt file
  • $Software = Array[8]
Test1:

From the script in test1 I want to call the function which is defined in test2.

The big problem which I am confronted with is transmitting the array "$Software" successfully without getting an array fault with the following code:

Local $avPakete[8] = [0,0,0,0,0,0,0,0]

$avPakete[0] = GUICtrlRead($cbx_1)

$avPakete[1] = GUICtrlRead($cbx_2)

$avPakete[2] = GUICtrlRead($cbx_3)

$avPakete[3] = GUICtrlRead($cbx_4)

$avPakete[4] = GUICtrlRead($cbx_5)

$avPakete[5] = GUICtrlRead($cbx_6)

$avPakete[6] = GUICtrlRead($cbx_7)

$avPakete[7] = GUICtrlRead($cbx_8)

PaketInstaller($SelSprache, $file, $avPakete, $InstPfad, $win, $arc)

When I call my function I always get the following error:

"Error Subscript used with non-Array variable"

Can somebody please help me how to use / define a function in AutoIT with an array as a parameter!?

Somehow I am not that experienced with Basic but with other languages I would have solved it easily but here I am totally mentally blocked at the moment :(

Many thanks in advance!

Greetings

Toco1982

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Toco1982,

What you have seems to work fine for me: ;)

; Simulate including test2:

Func PaketInstaller($InstSprache, $LogFileHandle, $Software, $Pfad, $WinVersion, $Architektur)

    MsgBox(0, "Here", "In the function")

EndFunc

; Here is test1
Local $avPakete[8] ; No need to define elements if you assign them later
Local $SelSprache, $file, $InstPfad, $win, $arc

; Simulate filling the array
$avPakete[0] = 1 ; GUICtrlRead($cbx_1)
$avPakete[1] = 1 ; GUICtrlRead($cbx_2)
$avPakete[2] = 1 ; GUICtrlRead($cbx_3)
$avPakete[3] = 1 ; GUICtrlRead($cbx_4)
$avPakete[4] = 1 ; GUICtrlRead($cbx_5)
$avPakete[5] = 1 ; GUICtrlRead($cbx_6)
$avPakete[6] = 1 ; GUICtrlRead($cbx_7)
$avPakete[7] = 1 ; GUICtrlRead($cbx_8)


PaketInstaller($SelSprache, $file, $avPakete, $InstPfad, $win, $arc)

MsgBox(0, "Here", "Back from the function")

Perhaps if you posted both complete scripts we might be able to spot where the problem lies. :)

M23

P.S. Welcome to the the AutoIt forum, by the way. :)

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thanks Melba23!

Sometimes I could kick myself :D

In my code I found a stupid defintion:

Local $Nordic = ["Schwedisch", "Dänisch", "Finnisch", "Norwegisch"]

... so there is the problem :thumbsup:

... so stupid >_<

Share this post


Link to post
Share on other sites

Toco1982,

Happens to us all. :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  
Followers 0