开发者

Passing array in function

开发者 https://www.devze.com 2023-04-09 23:47 出处:网络
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?

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

精彩评论

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

关注公众号