开发者

Passing array in function

I have an array that is read like this:

MyArray(0)='test'
MyArray(1)='test2'
MyArray(2)='test3'

How do I pas开发者_运维百科s this through a function?

Function(MyArray(all_arrays)) 

What do I put for all_arrays?


MyArray(0)='test'
MyArray(1)='test2
MyArray(2)='test3'

AcceptArray MyArray

Private Function AcceptArray(myArray())
'Code here
End Function

You look to want to pass a string before the array.

So, change the Function to :

Private Function AcceptArray(param1, myArray)
'Code here
'Don't forget to return value of string type.
End Function

And you call this function like this:

returnValue = AcceptArray("MyString", MyArray)

If you do not need to return a value you should use a Sub.


Looks like you need to define you function as such:

Function <FunctionName>(byref <list Name>)

then when you call it in your code use

<FunctionName>(MyArray)

found here: http://www.herongyang.com/VBScript/Function-Procedure-Pass-Array-as-Argument.html

passing by referrence using just the array name allows you to pass in the entire array to the function


A simple example...

Dim MyArray(2)
MyArray(0) = "Test"
MyArray(1) = "Test2"
MyArray(2) = "Test3"

ProcessArray MyArray

' -------------------------------------
' ProcessArray
' -------------------------------------
Sub ProcessArray(ArrayToProcess())
  For i = 0 To 2
    WScript.Echo ArrayToProcess(i)
  Next
End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜