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?
It is as simple as this :
Because when you use
Dim
, you have to specify for each variable what type is it, the previous code was declaring the first three asVariant
and only the last one asInteger
!Reference: How to declare variables in VBA