Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ARRAY declaration in GOSUB routines.
#19
(02-05-2024, 02:50 PM)bplus Wrote:
(02-05-2024, 02:40 PM)bartok Wrote:
(02-05-2024, 02:20 PM)bplus Wrote: Wow I did not know that about erase in subs in main this works fine!
Code: (Select All)
Dim a(3)
a(1) = 1
Print a(1); "prints 1 with no error"
Erase a
Print a(1); "error! the array has been freed and erased in the SUB"

I've used erase quite a bit, guess it's always been with ones dim'd in main or shared from main. oh let's try that!

Code: (Select All)
Dim Shared a(3)
foo


Sub foo
    a(1) = 1
    Print a(1); "prints 1 with no error"
    Erase a
    Print a(1); "error! the array has been freed and erased in the SUB"
End Sub
yes, no problem sharing from main!

@Bartok maybe that will work for you?
Yes, it works. An it works also like that:

Code: (Select All)
OPTION _EXPLICIT
DIM a(3)
foo

SUB foo
    SHARED a()
    a(1) = 1
    PRINT a(1); "prints 1 with no error"
    ERASE a
    PRINT a(1); "prints correctly 0 with no errors"
END SUB

But I don't want to do that in my code, because those arrays are local and there is absolutely no need to share them with the main code.
S, if the arrays is defined in the main code, ERASE set to "0" or "null". If the array is local, ERASE deletes it.

OK I can understand that, so Steve already pointed to sol'n of just using REDIM on temporary arrays, forget ERASE, REDIM you get 2 commands for price of 1! ;-))

BTW you can use REDIM in place of DIM for everything! Option _Explicit won't mind.
Actually, I found that there is no need to set to 0 those arrays... because, when "CalcolaIdrogramma" is CALLed, the GOSUB subroutine "interpola:" is used twice, and in both cases the arrays are completely overwritten. I think to have put the ERASE command "automatically". Even the comment I put in the commented version doesn't explain if there were some particular reason. It says only that they had to be resetted. But it has been interesting to know this particularity of ERASE.
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 bartok - 02-05-2024, 03:22 PM



Users browsing this thread: 1 Guest(s)