bungpeng Posted February 28, 2003 Posted February 28, 2003 Array class like ArrayList is a great class because we no need to define the size of array and it will automatic adjust, but how about if I want to use 2D array? can I still use class like ArrayList? how to do? Quote
bpayne111 Posted February 28, 2003 Posted February 28, 2003 I would try creating a class and use the two indexes as parameters in a default Item property. ie: public class WidgetArray private myWidgets(iCol*iRow) as widget inherits ArrayList 'override the methods you wish to use public default property Items (Byval x as Integer, ByVal y as Integer) as Widget get return mywidgets(x,y) end get set (byval value as widget) mywidgets(x,y) = value end set 'override add, remove and whatever else you need Quote i'm not lazy i'm just resting before i get tired.
*Gurus* Derek Stone Posted February 28, 2003 *Gurus* Posted February 28, 2003 Dim alMain As ArrayList = New ArrayList Dim iMain() As Integer = {1, 2, 3, 4, 5} alMain.Add(iMain) If you needed ArrayList-like functionability for the 2nd-dimension change the array into an ArrayList and add that instead. I would not recommend this method for large lists or processor intensive code blocks, nor is this a viable solution for all cases. Quote Posting Guidelines
bungpeng Posted March 1, 2003 Author Posted March 1, 2003 In this case I have to DIM every time I add a single record in ArrayList? Quote
bpayne111 Posted March 1, 2003 Posted March 1, 2003 there is almost never a need to do that just Dim it once... and then make new objects like so... Dim myThing as Object Dim myArray as ArrayList mything = new object(parameters) myArray.Add(mything) mything = new object(paramenters) (in reality you'd probably use a Sub and use the parameters from that Sub to instantiate your new object, that way you'd only have one statement..... 'x = new x(a,b,c setting abc when you call the sub) (obviously this is just a sample, so your needs will vary, but it's a shot) always tryin to help Quote i'm not lazy i'm just resting before i get tired.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.