Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CLEAR command
#10
CLEAR and ERASE and any other similar command has always just seemed too unreliable, in my opinion.  There's just too many various rules around their behavior.  Do they affect arrays?  variables?  dynamic?  static?  ones in SUBS/FUNCTIONS?   What gets erased?  What gets freed completlely?  

FOR I = 1 to 10
   x(1) = I
NEXT

CLEAR

FOR I = 1 to 10
   PRINT x(I)
NEXT

In the above, does x(I) just get reset to 0?  Does it get erased and freed completely?  After all, there's no call to DIM it before the first FOR, so it works just fine.   IS that second FOR reusing the same variable array which has been blanked to 0, or is it a whole new array?

It's not immediately obvious what the heck is going on here, and personally I don't like that ambiguity in my code.  When I'm editing and working on something at 2 AM, after a long 18-hour day, I don't want to have to dig up some manual or wrack my brain on how some esoteric and forgotten command works.   I want to keep things simple:


FOR I = 1 to 10
   x(1) = I
NEXT

ResetArrays

FOR I = 1 to 10
   PRINT x(I)
NEXT

SUB ResetArrays
    SHARED X()
    FOR i = LBOUND(X) TO UBOUND(X)
       X(I) = 0
    NEXT
END SUB

No questions there about what's going on.   It's the same array.  Same position in memory, with the same offsets and such.  It's just had all its values reset to the default of 0.   Simple.  No questions about what's going on and what is actually doing what where.  It's resetting and initializing my arrays to 0.

What could possibly be simpler, or better than that?
Reply


Messages In This Thread
CLEAR command - by bartok - 02-02-2024, 10:13 PM
RE: CLEAR command - by TerryRitchie - 02-03-2024, 02:53 AM
RE: CLEAR command - by bartok - 02-03-2024, 09:52 AM
RE: CLEAR command - by TerryRitchie - 02-03-2024, 04:35 PM
RE: CLEAR command - by bartok - 02-03-2024, 09:11 PM
RE: CLEAR command - by bartok - 02-03-2024, 02:48 PM
RE: CLEAR command - by TerryRitchie - 02-03-2024, 04:29 PM
RE: CLEAR command - by bartok - 02-03-2024, 06:26 PM
RE: CLEAR command - by TerryRitchie - 02-03-2024, 05:22 PM
RE: CLEAR command - by bartok - 02-03-2024, 06:16 PM
RE: CLEAR command - by SMcNeill - 02-03-2024, 06:32 PM
RE: CLEAR command - by bartok - 02-03-2024, 08:20 PM
RE: CLEAR command - by SMcNeill - 02-03-2024, 10:24 PM
RE: CLEAR command - by TerryRitchie - 02-03-2024, 10:55 PM
RE: CLEAR command - by bartok - 02-04-2024, 09:56 AM
RE: CLEAR command - by bplus - 02-03-2024, 06:41 PM
RE: CLEAR command - by TerryRitchie - 02-03-2024, 06:48 PM
RE: CLEAR command - by SMcNeill - 02-04-2024, 12:17 PM
RE: CLEAR command - by bartok - 02-04-2024, 01:13 PM
RE: CLEAR command - by Dimster - 02-04-2024, 03:26 PM
RE: CLEAR command - by bplus - 02-04-2024, 04:16 PM



Users browsing this thread: 3 Guest(s)