Reputation: 89
I have defined a function in VBA as follows:
Sub TestFunction()
Dim ArrayLength, IDvariable, IDComparisonResult, PreArrayLength As Integer
ReDim NodesArray(0)
PreArrayLength = 0
IDvariable = 0
.
.
Sort PreArrayLength
End Sub
whereas the function called is as follows:
Sub Sort (PreArrayLength As Integer)
.
.
.
end sub
Above function runs nicely but if I change declaration in TestFunction() as
Dim ArrayLength, IDvariable, PreArrayLength, IDComparisonResult As Integer
my code gives me an error "ByRef Argument type mismatch" indicating the line
Sort PreArrayLength
Can anyone point the mistake I am making in declaration or understanding the error?
Upvotes: 0
Views: 117
Reputation: 14537
It is as simple as this :
Dim ArrayLength As Integer, _
IDvariable As Integer, _
PreArrayLength As Integer, _
IDComparisonResult As Integer
Because when you use Dim
, you have to specify for each variable what type is it, the previous code was declaring the first three as Variant
and only the last one as Integer
!
Reference: How to declare variables in VBA
Upvotes: 2