I’m trying to use ReDim Preserve to copy the contents of an array within a user-defined type but I am getting an Object Required error (error number 424) at the line just before the ReDim in the following (as commented):
type _t1 i as integer s as string end type type _t2 j as integer t() as _t1 end type type _t3 k as integer t2() as _t2 end type private function copy_t3(src as _t3) as _t3 dim copy as _t3 dim t2a(1 to 5, 1 to 5) as _t2 ' _t2 array used to copy the array's data ' Copy t3-level data copy.k = src.k t2a = src.t2 ' <<<< ERROR OCCURS HERE redim preserve t2a(1 to 5, 1 to 5) as _t2 copy.t2 = t2a end function Sub Main dim x as _t3 dim y(1 to 5, 1 to 5) as _t2 ' fill y for ii = 1 to 5 for jj = 1 to 5 y(ii,jj).j = ii * 10 + jj ' I'm ignoring the fact that _t2 contains an array for now... next jj next ii x.t2 = y dim cpy as _t3 cpy = copy_t3(x) End Sub
I’ve spent all afternoon trying all sorts of syntax variations and trying to google an answer to no avail. As a relative noob to LibO Basic, I think I’m missing something. Does anyone have any ideas as to what? Or, if you have an example solution to the general problem of copying a user-defined data type, that’d be helpful too.
And to be clear, I’m looking for a duplicate variable, not just a pointer to the same copy of data. I want to change the data in cpy without changing the data in x.
Any pointers would be greatly appreciated! Thanks!!