problem with passing array parameter to the procedure
-
Hi I have some procedure: Sub SomeSub(ByRef somearray() As Double) 'some code, it doesn't matter End Sub I'm trying to call it in this way: Dim somearray(10) As Double SomeSub (somearray) And I get such error message(it's my translation from polish, so it might be different on your computers): Compilation error: Argument of type Array must be passed by reference (ByRef) I don't know what is wrong. I almost forgot to add, all the code is runned as a macro in Word97 Greetings
-
Hi I have some procedure: Sub SomeSub(ByRef somearray() As Double) 'some code, it doesn't matter End Sub I'm trying to call it in this way: Dim somearray(10) As Double SomeSub (somearray) And I get such error message(it's my translation from polish, so it might be different on your computers): Compilation error: Argument of type Array must be passed by reference (ByRef) I don't know what is wrong. I almost forgot to add, all the code is runned as a macro in Word97 Greetings
Try adding the word
Call
in front of your routine call, this should do the trick, it works on my computer.Private Sub Form_Load()
Dim MyArray(10) As Double
Call
Some(MyArray)End Sub
Sub Some(ByRef SomeArray() As Double)
MsgBox "Hello"
End Sub
-
Try adding the word
Call
in front of your routine call, this should do the trick, it works on my computer.Private Sub Form_Load()
Dim MyArray(10) As Double
Call
Some(MyArray)End Sub
Sub Some(ByRef SomeArray() As Double)
MsgBox "Hello"
End Sub
-
No problem. :) Nick Parker
-
Hi I have some procedure: Sub SomeSub(ByRef somearray() As Double) 'some code, it doesn't matter End Sub I'm trying to call it in this way: Dim somearray(10) As Double SomeSub (somearray) And I get such error message(it's my translation from polish, so it might be different on your computers): Compilation error: Argument of type Array must be passed by reference (ByRef) I don't know what is wrong. I almost forgot to add, all the code is runned as a macro in Word97 Greetings
This small example will help to understand the role of "()" around the argument
Sub Func(ByRef i As Long) i = 12 End Sub Private Sub Form_Load() Dim j As Long j = 33 Call Func(j) ' **ByRef** Debug.Print "j="; j ' the output will be: j= **12** j = 33 Call Func((j)) ' **ByVal** Debug.Print "j="; j ' the output will be: j= **33** j = 33 Func (j) ' **ByVal**. Note that there is the space between function name and argument Debug.Print "j="; j ' the output will be: j= **33** Unload Me End Sub
With best wishes, Vita