Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can values assigned with DIM be reinitialized?
#2
No, there's no way for this, because when you declare with DIM a variable you're just declaring it (reserving memory) with a default value. So using a second assignation to reinitialize it, is not such a memory waste.

For arrays, the classic way to to that is to use READ, DATA, RESTORE to populate the array.
Other (faster) way is to initialize the array the way you did in a temporary one, and assign it upon start:

Code:
DIM struCopy(3,9) AS UBYTE => {{1,0,0,1,0,1,0,1,0}, {0,3,3,0,4,0,4,0,5}, {0,30,30,0,60,0,50,0,70}}

start:
   stru = struCopy : REM copies the array into stru

...

This way is the recommended and takes the same memory (any default value must be saved somewhere to be copied again upon re-start).
A more elegant way is to use REDIM (which is equivalent to Sinclair BASIC DIM in the sense it's executed everytime the executions reaches its point). I'm working on it, but it's not yet finished.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)