This code compiles with an error, saying that MyArray is not dimensioned (the offending line is commented).
But as the program would execute, a Dim would be applied to MyArray before the offending statement would be seen - via the MyOtherSub which has MyArray passed to it for DIM'ing.
Shouldn't this compile without error?
Since the array is DIM'd under another name (a ByRef argument), I assume the compiler simply doesn't catch what's happening and gives the error. But I would have guessed that since the program logic allows DIMing before the offending line is reached, that the compiler would not have stated an error is present.
I guess I haven't tried this "hidden" DIMing of an array before, to have seen the error the compiler gives.
Is this consistent with what others have seen?
As a workaround, I can DIM the array explicitly and use REDIM in MyOtherSub.
BTW - in my bigger app, the MyOtherSub may be used to DIM any one of several different arrays (along with taking action on the array content) - hence the use of a Sub argument instead of explicitly DIMing the array by its original name.
But as the program would execute, a Dim would be applied to MyArray before the offending statement would be seen - via the MyOtherSub which has MyArray passed to it for DIM'ing.
Shouldn't this compile without error?
Since the array is DIM'd under another name (a ByRef argument), I assume the compiler simply doesn't catch what's happening and gives the error. But I would have guessed that since the program logic allows DIMing before the offending line is reached, that the compiler would not have stated an error is present.
I guess I haven't tried this "hidden" DIMing of an array before, to have seen the error the compiler gives.
Is this consistent with what others have seen?
As a workaround, I can DIM the array explicitly and use REDIM in MyOtherSub.
Code:
#Compile Exe #Dim All Global MyArray() As String Function PBMain () As Long MySub ? "done" End Function Sub MySub() MyOtherSub(MyArray()) MyArray(5) = "test" 'this line gives the errror End Sub Sub MyOtherSub(TheArray() As String) Dim TheArray(25) End Sub
Comment