passing array as parameter to a subroutine problem

Andrew XJ

Board Regular
Joined
Feb 21, 2002
Messages
77
I met the case that array parameter passing failed.
My testing code is as following:
Option Base 1
Sub test(ParamArray array1() As Variant)
MsgBox "Ubound(array1) is " & UBound(array1)
End Sub

Sub main()
Dim array2(2) As String
array2(1) = "ABC"
array2(2) = "BCD"
MsgBox "Ubound(array2) is " & UBound(array2())
test(array2)
End Sub

I run subroutine main. The result is that:
Ubound(array2) is 2
Ubound(array1) is 0

Seems that array2 is not passed to subroutine test.
Could you help me with it?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
It works this way..

Sub test(array1() As String)
MsgBox "Ubound(array1) is " & UBound(array1)
End Sub

Sub main()
Dim array2(2) As String
array2(1) = "ABC"
array2(2) = "BCD"
MsgBox "Ubound(array2) is " & UBound(array2())
Call test(array2)
End Sub

Regards, Trevor
 
Upvote 0

Forum statistics

Threads
1,214,574
Messages
6,120,327
Members
448,956
Latest member
Adamsxl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top