Serving the Quantitative Finance Community

 
User avatar
hunting
Topic Author
Posts: 1
Joined: February 15th, 2004, 5:18 pm

VBA Programming Question

October 21st, 2004, 6:57 pm

Hey..Can anyone help me with something? I want to make a 21 x 1 array, where each entry of the array is itself a vector of dates. However, each of the vectors is of a different dimension. I could always make a matrix of n x 21 where n is the maximum dimensionality of the individual vectors, and backfill with zeroes for the rest; but I was hoping for a cleaner solution. Any advice?Thanks and best rgds
 
User avatar
magriggs
Posts: 0
Joined: October 19th, 2004, 9:23 pm

VBA Programming Question

October 21st, 2004, 7:47 pm

Hmmm, easy to do in C++ or a similar language, but I don't know about VBA. Can you assign an array member to be a pointer to another array? I suspect not. The n x 21 might be your only choice, sadly :-(
 
User avatar
daveangel
Posts: 5
Joined: October 20th, 2003, 4:05 pm

VBA Programming Question

October 21st, 2004, 8:58 pm

does it have to be an array ? you could use a collection
knowledge comes, wisdom lingers
 
User avatar
Russell
Posts: 1
Joined: October 16th, 2001, 5:18 pm

VBA Programming Question

October 22nd, 2004, 5:54 am

in VBA:dim arr1(1 to 21) as variantarr(i) = datevectorthen arr(i)(j) gives you the jth element of the ith vector
 
User avatar
FastExcel
Posts: 3
Joined: December 2nd, 2003, 8:10 am

VBA Programming Question

October 22nd, 2004, 6:02 am

You can do it using variants:Sub RaggedVar()Dim vArr(4) As VariantDim vArr2(6) As VariantvArr2(2) = "Fred"vArr(1) = Array(1, 2, 3, 4)vArr(2) = vArr2MsgBox vArr(1)(1)MsgBox vArr(2)(2)End SubRun the above in debug mode and look at Varr in the locals window to see whats happening.
 
User avatar
afoster
Posts: 5
Joined: July 14th, 2002, 3:00 am

VBA Programming Question

October 22nd, 2004, 7:57 am

I assume when you say Vector, you are talking about an object container type, similar to the ones found in the C++ STL. If this is the case, you simply Dim your array as a Vector type. If you haven't got a vector class to hand - attached is a code sample.
 
User avatar
hunting
Topic Author
Posts: 1
Joined: February 15th, 2004, 5:18 pm

VBA Programming Question

October 26th, 2004, 12:48 pm

many thanks to all!