Jump to content

Pass array directly to function? getData(["Child from A Item 0", "Child from A Item 1"])


Recommended Posts

Can I pass an array directly to a function?

local $ArrData[2]=["Child from A Item 0", "Child from A Item 1"]
getData($ArrData)
getData(["Child from A Item 0", "Child from A Item 1"])

func getData($arr)
    consolewrite($arr[0] & @CRLF)
    consolewrite($arr[1] & @CRLF)
EndFunc

gives error  ==> Error in expression.:

getData(["Child from A Item 0", "Child from A Item 1"])
getData(^ ERROR

 

Link to comment
Share on other sites

Hi @junkew.

No i don't think you can.

If you want to use an array directly, something like this maybe:

getData(StringSplit("Child from A Item 0,Child from A Item 1",",",2))

 

Link to comment
Share on other sites

You can use the first form of your call to the function, the second one won't work.

This will work fine to pass an array to the function.

getData($ArrData)

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Ok then I will change it to something like this (any coding advice on this? my arguments are fixed to 4)

Below I feel is cleaner then a stringsplit but any other way of coding is welcome

Set $NetCollection=ObjCreate("System.Collections.Sortedlist")

$NetCollection.Add("one", getDataArray("Child A from one", "Child B from one", "Child C from one", "Child D from one"))
$NetCollection.Add("two", getDataArray("Child A from two", "Child B from two", "Child C from two", "Child D from two"))

...
func getDataArray($v1, $v2, $v3, $v4, ..., $v255) 
    $arr[4]
    
    $arr[0]=$v1
    $arr[1]=$v2
    $arr[2]=$v3
    $arr[3]=$v4
    
    return $arr
endfunc

 

Link to comment
Share on other sites

Why don't you just create the array, then pass it to the function? Isn't that what you asked about?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

local $ArrData[2]

$ArrData[0]="Child A from one", "Child B from one", "Child C from one", "Child D from one"
$ArrData[1]="Child A from two", "Child B from two", "Child C from two", "Child D from two"

Set $NetCollection=ObjCreate("System.Collections.Sortedlist")

$NetCollection.Add("one", $arrData[0])
$NetCollection.Add("two", $arrData[1])

Background

I am playing a little around with treeview, listview and .NET collections (to enhance simplespy of Examples IUIAutomation thread) and as an end result where you see "one", "two" i should have the handle of the treeviewitem so easy and quick to lookup data in a limited set of rows in a collection/array (I assume below 1000 items in the treeview).

So the array is not static upfront (will contain the UIA property information which either is collected on the fly or coming from an XML or INI file)

Edited by junkew
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...