Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ARRAY declaration in GOSUB routines.
#9
Looks to me like everything is working as it's supposed to.

You move that DIM up to the start of the program.

Then you have a GOSUB routine that uses it....
Then you ERASE that DIM at the end of that GSOUB routine, before the RETURN...
Then you try and GOSUB back to that routine to use it....

ERROR ERROR ERROR!!  You're out of bounds for an array that doesn't exist!!



Now, take that ERASE out of there and run it.   You now are getting an ALREADY DEFINED error.  This is expected as well:

Code: (Select All)
foo
Sub foo
    For i = 1 To 10
        Dim x(10)
    Next
End Sub

Trying to DIM an array inside a loop isn't a good idea.

Change that to REDIM, and you're golden.



So my advice here:  

1) Get rid of ERASE and CLEAR.  This is the type of glitches that are common when you use those commands.  Expect to have them pop up a lot on you as you code.
2) Change that DIM to REDIM, since you're going to be remaking this array repeatedly.
3) Then place it wherever the heck you want it.
Reply


Messages In This Thread
ARRAY declaration in GOSUB routines. - by bartok - 02-04-2024, 01:05 PM
RE: ARRAY declaration in GOSUB routines. - by SMcNeill - 02-04-2024, 10:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  getting the number of dimensions in an array on the fly? madscijr 7 745 09-16-2025, 12:34 AM
Last Post: madscijr
  Quesiton on Dimensioning an Array Dimster 5 1,000 02-06-2024, 01:55 PM
Last Post: Dimster
  Array in an array NasaCow 78 15,610 04-12-2023, 10:53 AM
Last Post: TempodiBasic
  Can images be read from a file into an array? PhilOfPerth 11 2,535 02-17-2023, 03:31 AM
Last Post: TerryRitchie
  Swapping array elements PhilOfPerth 24 3,919 11-19-2022, 12:16 AM
Last Post: Pete

Forum Jump:


Users browsing this thread: 1 Guest(s)