(02-04-2024, 10:47 PM)SMcNeill Wrote: Looks to me like everything is working as it's supposed to.Thank's you. I have understood where is the problem. But I don't have understood how REDIM can solve it. Furthermore, I wonder why "ERASE k, costruisci, x%" makes k, costruisci, x% inexistent.
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.
Code: (Select All)
OPTION _EXPLICIT
DIM a%(1)
a%(1) = 1
PRINT a%(1)
'PRINT a%(2)-----> get an error.
ERASE a%
PRINT a%(1) '------> it gives "0".
'PRINT a%(2)-----> get an error.
It seems that ERASE set a%() to 0, without deleting a%(). So, why " k, costruisci, x%" do not exist after ERASE? Of course I can reset "k, costruisci, x%" with a cicle FOR we said on the discussion about CLEAR, but I am disapponted about what I don't understand.
Furthermore, the other 2 ERASE command into the code:
'Erase IdroPixel1, IdroPixel2, idrogramma1, idrogramma2
&
'Erase idrogrammi1a24, MassimiIdrogrammi1a24, FinePioggiaIdrogrammi1a24, MassimiAssolutiIeto, IdroMaxieto%%, FinePioggiaIdrogrammi1e2, PassiFinePioggia1a24%%, IdroPixel1, IdroPixel2, idrogramma1, idrogramma2, dt!,_
'matrice1, matrice2!, MinimiMatriciQuadrante1, MinimiMatriciQuadrante2, MassimiQuadrante2
that don't give at all the problem, but they are in the DO loops allowing the program to be navigable. So, if these ERASE deletes the arrays, why I don't get errors? There must be something.
UPDATE
Making the same of the above example using a SUB, it brings to OUT OF RANGE error.
Code: (Select All)
OPTION _EXPLICIT
CALL ciao
END
SUB ciao
DIM a%(1)
a%(1) = 1
PRINT a%(1)
'PRINT a%(2)-----> get an error.
ERASE a%
PRINT a%(1) '------> get an error.
'PRINT a%(2)-----> get an error.
END SUB
That explains why I don't have problems with the ERASEs inside the main code, but I have the problem inside a SUB. Then the question is: it's a problem about ERASE, or there is something that I'm doing wrong?