OK I tried to make up an example following your Case B example:
The above is redlined and won't work because the DIM Minus(1 to 100) line is NOT seen in the Say Sub main code area.
OK I fix the little bit of code by moving DIM Minus() array up to declares section of Say sub:
And it works fine! It's a dumb example but does show how you should declare all varaibles and arrays at top of subroutine or main code NOT under the GOSUB line label.
Code: (Select All)
Option _Explicit
_Title "Test array declaration in GoSub" ' b+ 2024-02-04
Dim x As Integer
x = 10
Call say(x)
End
Sub say (n)
Dim i As Integer
GoSub test:
i = 1
While i <> n
i = i + 1
Wend
Print minus(i) ' here I have to move Dim Minus(1 to 100) to top of sub because Minus must be declared even though the Gosub test is called and array is DIM'd before I actually use the array in the Sub code!!!
Exit Sub
test:
Dim minus(1 To 100) As Integer
For i = 1 To 100
minus(i) = 100 - i
Next
Return
End Sub
OK I fix the little bit of code by moving DIM Minus() array up to declares section of Say sub:
Code: (Select All)
Option _Explicit
_Title "Test array declaration in GoSub" ' b+ 2024-02-04
Dim x As Integer
x = 10
Call say(x)
End
Sub say (n)
Dim i As Integer
Dim minus(1 To 100) As Integer
GoSub test:
i = 1
While i <> n
i = i + 1
Wend
Print minus(i) ' here I have to move Dim Minus(1 to 100) to top of sub
Exit Sub
test:
For i = 1 To 100
minus(i) = 100 - i
Next
Return
End Sub
And it works fine! It's a dumb example but does show how you should declare all varaibles and arrays at top of subroutine or main code NOT under the GOSUB line label.
b = b + ...