Sign in to follow this  
Followers 0
JohnBailey

Array in function parameters

9 posts in this topic

#1 ·  Posted (edited)

I want to put an array in the function parameter

#include<Array.au3>

example([1,2,3,4])
Func example($array)
  _ArrayDisplay($array)
EndFunc

ANSWER: #364268

Edited by JohnBailey

A decision is a powerful thing

Share this post


Link to post
Share on other sites



I want to put an array in the function parameter

#include<Array.au3>

example([1,2,3,4])
Func example($array)
  _ArrayDisplay($array)
EndFunc
Why? What are you trying to do?

Share this post


Link to post
Share on other sites

I started the following thread, then realized there is too much to communicate (it's convoluted like crazy). Thus, I wanted to break the concepts and questions into separate threads and then answer my own question in the following thread:

http://www.autoitscript.com/forum/index.php?showtopic=48456

In a few mins, I'll post a very inefficient and messy form of what I'm wanting to do, but it will be a functioning version at least.


A decision is a powerful thing

Share this post


Link to post
Share on other sites

You need to pass an array...otherwise your sending a string.

$aStuff = array('1','2','3','4','5')
example($aStuff)

You can also do ByRef type passes as well when defining your function....it's up to you how you want to pass this stuff around.


Sean Shrum :: http://www.shrum.net

All my published AU3-based apps and utilities

'Make it idiot-proof, and someone will make a better idiot'

 

Share this post


Link to post
Share on other sites

I want to put an array in the function parameter

You can build you function to accept both single values and arrays of values:

_FuncTest("2")
_FuncTest(3)
$x = 4
_FuncTest($x)
_FuncTest("2 | 4 | 6 | 8")
Dim $avTest[3] = [3,4,5]
_FuncTest($avTest)

Func _FuncTest($Input)
    Local $Msg = "Processing ", $n
    If IsArray($Input) Then
        $Msg &= "multiple columns: "
        For $n = 0 to UBound($Input) - 1
            $Msg &= $Input[$n] & " | "
        Next
        $Msg = StringTrimRight($Msg, 3)
    ElseIf StringInStr($Input, "|") Then
        $Msg &= "multiple columns: " & $Input
    Else
        $Msg &= "a single column: " & $Input
    EndIf
    MsgBox(64, "_FuncTest()", $Msg)
EndFunc

:rolleyes:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

You need to pass an array...otherwise your sending a string.

$aStuff = array('1','2','3','4','5')
example($aStuff)
array isn't a function. Did you mean I should make it a function or use _ArrayCreate() ?

You can also do ByRef type passes as well when defining your function....it's up to you how you want to pass this stuff around.

I'm not sure how that works out with this? I don't totally understand ByRef. I've read up on it in the manual, but I don't know why it's important.

(thank you thus far!)


A decision is a powerful thing

Share this post


Link to post
Share on other sites

You can build you function to accept both single values and arrays of values:

VERY good point.


A decision is a powerful thing

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