QB64.org Forum
Active Forums => Programs => Topic started by: SMcNeill on December 02, 2019, 09:29:41 am
-
Every so often, someone will ask, "Why can't we use arrays with User Defined Types?" The answer to that, is of course, "No one coded BASIC to work like that, and the functionality hasn't been expanded for it yet."
Which, leaves us with trying to find a workaround for easy transfer of data via GET/PUT statements...
Here's the easiest way I've found to do this type of thing, and I thought I'd shared for those who might be interested:
m
= _MEM(b
()) 'a memblock to point at our arraym1
= _MEM(foo.s
) 'and one to point at our user type string to hold the array
b(x, y) = count
count = count + 1
SLEEP 'So we can see what b() contains.
_MEMCOPY m
, m.OFFSET
, m.SIZE
TO m1
, m1.OFFSET
'Copy our array to our User Type Variable
SLEEP 'So we can see that b() is now blank.
m
= _MEM(b
()) 'point our mem blocks back, since CLEAR erased them...
_MEMCOPY m1
, m1.OFFSET
, m1.SIZE
TO m
, m.OFFSET
'Copy our User Type Variable back to our array b(x, y) = count
count = count + 1
-
??? Since when this is possible ???
Wiki doesn't mention this kind of usage.
-
??? Since when this is possible ???
Wiki doesn't mention this kind of usage.
Actually that's a classic "Steve Oopsie". ERASE b() would be more appropriate to just erase the arrays, but CLEAR, in this case, works well enough here (though the b() is ignored).
The ERASE statement is used to clear all data from an array
The CLEAR statement clears all variable and array element values in a program.