Re: [Gambas-user] Multidimensional dynamic array basics
Well you need to understand that you make an array of array of models To fill it : Public StageListWall As New ObjModel[][] StageListWall.Resize(200) 'Instanciate each x Level For i = 1 to StageListWall.Max StageListWall[i] = new objModel[] next 'Adding a Model : hModel = new ObjModel StageListWall[0].Add(hModel) 'To get the Model name if you have a property name : StageListWall[0][0].Name To Delete a model StageListWall[0].Delete(0) To clear All model of x level StageListWall[x].Clear Well i prefer far this kind of array and use it more than the multidimentionnal way. At gambas begin there was only Objects and array of objects... so the Array of array was the only way to get multidimentionnal array. I have not found any qualities to the multidimentional way .. maybe the speed ? Le 21 août 2015 09:39, Gianluigi bagone...@gmail.com a écrit : Provided that the Sardinia sun has baked my brain (in fact, since my last post, it would seem) example (I think correctly) that I posted, there is what you need and more. Greetings Gianluigi 2015-08-21 9:19 GMT+02:00 Tobias Boege tabo...@gmail.com: On Fri, 21 Aug 2015, Kevin Fishburne wrote: On 08/21/2015 12:00 AM, Kevin Fishburne wrote: On Wed, Aug 19, 2015 at 9:22 AM, Kevin Fishburne kevinfishbu...@eightvirtues.com wrote: I need to know how to declare, initialize and add elements to a two-dimensional dynamic array. Using trial-and-error for every possible syntax hasn't been too helpful so far. I'd post my code but it's pretty useless and embarrassing and I think the basic question sums it up. On 08/19/2015 08:17 AM, Jussi Lahtinen wrote: You can't do it dynamically with normal syntax: Dim iMyArray As Integer[x, y] Instead use declaration like this: Dim iMyArray As Integer[][] But then, you can't access it as the normal way (iMyArray[x, y]) either, but instead: iMyArray[x][y] = something iMyArray[x].Add(something) iMyArray[x][y].Add(something) So, it's really array of arrays. Thanks everyone for the responses. The whole quadruple bracket thing [][] is what was confusing me. It's all good now. :) Okay, I was wrong. I still don't know what I'm doing. I need to dynamically add elements to SomeArray[][] and the syntax eludes me. I start with this: Public StageListWall As ObjModel[][] StageListWall = New ObjModel[][] Then madness and stupidity ensues (this is but one example of dozens of combinations I've tried): StageListWall.Add([Null]) StageListWall[0].Add(Null) Obviously that doesn't work, but at this point I'm trying first to avoid syntax errors and second to actually get it working and understand why. I don't see why this wouldn't work. It does in my attached project. Regards, Tobi -- There's an old saying: Don't change anything... ever! -- Mr. Monk -- ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user -- ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user -- ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] Multidimensional dynamic array basics
On Fri, 21 Aug 2015, Kevin Fishburne wrote: On 08/21/2015 12:00 AM, Kevin Fishburne wrote: On Wed, Aug 19, 2015 at 9:22 AM, Kevin Fishburne kevinfishbu...@eightvirtues.com wrote: I need to know how to declare, initialize and add elements to a two-dimensional dynamic array. Using trial-and-error for every possible syntax hasn't been too helpful so far. I'd post my code but it's pretty useless and embarrassing and I think the basic question sums it up. On 08/19/2015 08:17 AM, Jussi Lahtinen wrote: You can't do it dynamically with normal syntax: Dim iMyArray As Integer[x, y] Instead use declaration like this: Dim iMyArray As Integer[][] But then, you can't access it as the normal way (iMyArray[x, y]) either, but instead: iMyArray[x][y] = something iMyArray[x].Add(something) iMyArray[x][y].Add(something) So, it's really array of arrays. Thanks everyone for the responses. The whole quadruple bracket thing [][] is what was confusing me. It's all good now. :) Okay, I was wrong. I still don't know what I'm doing. I need to dynamically add elements to SomeArray[][] and the syntax eludes me. I start with this: Public StageListWall As ObjModel[][] StageListWall = New ObjModel[][] Then madness and stupidity ensues (this is but one example of dozens of combinations I've tried): StageListWall.Add([Null]) StageListWall[0].Add(Null) Obviously that doesn't work, but at this point I'm trying first to avoid syntax errors and second to actually get it working and understand why. I don't see why this wouldn't work. It does in my attached project. Regards, Tobi -- There's an old saying: Don't change anything... ever! -- Mr. Monk array-test-0.0.1.tar.gz Description: Binary data -- ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] Multidimensional dynamic array basics
On 08/21/2015 12:00 AM, Kevin Fishburne wrote: On Wed, Aug 19, 2015 at 9:22 AM, Kevin Fishburne kevinfishbu...@eightvirtues.com wrote: I need to know how to declare, initialize and add elements to a two-dimensional dynamic array. Using trial-and-error for every possible syntax hasn't been too helpful so far. I'd post my code but it's pretty useless and embarrassing and I think the basic question sums it up. On 08/19/2015 08:17 AM, Jussi Lahtinen wrote: You can't do it dynamically with normal syntax: Dim iMyArray As Integer[x, y] Instead use declaration like this: Dim iMyArray As Integer[][] But then, you can't access it as the normal way (iMyArray[x, y]) either, but instead: iMyArray[x][y] = something iMyArray[x].Add(something) iMyArray[x][y].Add(something) So, it's really array of arrays. Thanks everyone for the responses. The whole quadruple bracket thing [][] is what was confusing me. It's all good now. :) Okay, I was wrong. I still don't know what I'm doing. I need to dynamically add elements to SomeArray[][] and the syntax eludes me. I start with this: Public StageListWall As ObjModel[][] StageListWall = New ObjModel[][] Then madness and stupidity ensues (this is but one example of dozens of combinations I've tried): StageListWall.Add([Null]) StageListWall[0].Add(Null) Obviously that doesn't work, but at this point I'm trying first to avoid syntax errors and second to actually get it working and understand why. To bring context to the situation, in each stage there are x number of wall positions and y number of wall models per position, so assuming I can add elements to StageListWall[][] when loading the wall model display lists I would be able to access/refer to them like this: StageListWall[Position][DisplayList] There are an arbitrary number of positions and display lists per position. I also can't seem to refer to the length of individual arrays, such as by doing: StageListWall[].Length or StageListWall[][].Length The basic logic is that I would be referring to an individual display list using two numbers, position and list index. The display list itself would be the element value. If it were a static array it would look like this: Public StageListWall[1000, 1000] as ObjModel StageListWall[Position, DisplayList].Draw The logic for the static array is dead simple, yet translating this to a dynamic array is just killing me. Obviously I can just implement it as static and make it work, but I'd like to do it the proper/efficient way if it's possible. Any help is appreciated. -- Kevin Fishburne Eight Virtues www: http://sales.eightvirtues.com e-mail: sa...@eightvirtues.com phone: (770) 853-6271 -- ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] Multidimensional dynamic array basics
I posted an example (array of arrays) that contains at least this error: In routine: Public Sub Button3_Click() The line: If iR = -1 Then iR = $iContoRighe, should be replaced with: If iR = 0 Then iR = $iContoRighe I apologize (I am on vacation :)) Greetings Gianluigi 2015-08-19 10:22 GMT+02:00 Gianluigi bagone...@gmail.com: Hello Kevin, I'm on vacation and I'm not sure I understand the question, I am attaching this example in Italian perhaps with Google Translator can help. Regards Gianluigi 2015-08-19 8:22 GMT+02:00 Kevin Fishburne kevinfishbu...@eightvirtues.com : I need to know how to declare, initialize and add elements to a two-dimensional dynamic array. Using trial-and-error for every possible syntax hasn't been too helpful so far. I'd post my code but it's pretty useless and embarrassing and I think the basic question sums it up. -- Kevin Fishburne Eight Virtues www: http://sales.eightvirtues.com e-mail: sa...@eightvirtues.com phone: (770) 853-6271 -- ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user -- ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] Multidimensional dynamic array basics
On Wed, Aug 19, 2015 at 9:22 AM, Kevin Fishburne kevinfishbu...@eightvirtues.com wrote: I need to know how to declare, initialize and add elements to a two-dimensional dynamic array. Using trial-and-error for every possible syntax hasn't been too helpful so far. I'd post my code but it's pretty useless and embarrassing and I think the basic question sums it up. On 08/19/2015 08:17 AM, Jussi Lahtinen wrote: You can't do it dynamically with normal syntax: Dim iMyArray As Integer[x, y] Instead use declaration like this: Dim iMyArray As Integer[][] But then, you can't access it as the normal way (iMyArray[x, y]) either, but instead: iMyArray[x][y] = something iMyArray[x].Add(something) iMyArray[x][y].Add(something) So, it's really array of arrays. Thanks everyone for the responses. The whole quadruple bracket thing [][] is what was confusing me. It's all good now. :) -- Kevin Fishburne Eight Virtues www: http://sales.eightvirtues.com e-mail: sa...@eightvirtues.com phone: (770) 853-6271 -- ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] Multidimensional dynamic array basics
You can't do it dynamically with normal syntax: Dim iMyArray As Integer[x, y] Instead use declaration like this: Dim iMyArray As Integer[][] But then, you can't access it as the normal way (iMyArray[x, y]) either, but instead: iMyArray[x][y] = something iMyArray[x].Add(something) iMyArray[x][y].Add(something) So, it's really array of arrays. Jussi On Wed, Aug 19, 2015 at 9:22 AM, Kevin Fishburne kevinfishbu...@eightvirtues.com wrote: I need to know how to declare, initialize and add elements to a two-dimensional dynamic array. Using trial-and-error for every possible syntax hasn't been too helpful so far. I'd post my code but it's pretty useless and embarrassing and I think the basic question sums it up. -- Kevin Fishburne Eight Virtues www: http://sales.eightvirtues.com e-mail: sa...@eightvirtues.com phone: (770) 853-6271 -- ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user -- ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
[Gambas-user] Multidimensional dynamic array basics
I need to know how to declare, initialize and add elements to a two-dimensional dynamic array. Using trial-and-error for every possible syntax hasn't been too helpful so far. I'd post my code but it's pretty useless and embarrassing and I think the basic question sums it up. -- Kevin Fishburne Eight Virtues www: http://sales.eightvirtues.com e-mail: sa...@eightvirtues.com phone: (770) 853-6271 -- ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] Multidimensional dynamic array basics
Personally, I like to think of a 2D array of integers as a 1D array of objects, with each element an array of integers I've done something like this with complete success: ' Public rec As New Object[100]'declare rec as an array of objects and create it. ...then... in Sub _new() Dim i As Integer Dim ia As Integer[] 'This declares what ia is, but doesn't create it yet For i = 0 To 99 ia = New Integer[10] 'This creates a new array of integers[0..9] each loop rec[i] = ia'Each element of rec[] now contains a created Integer[10] array Next ' ...something else... rec[15][3] = 86400 'just like a 2D integer array rec.delete(7) 'will remove rec[7] (the whole integer array at rec[7]) and bumps down whole arrays rec[8]..rec[99] to be rec[7]..rec[98] rec[20].delete(3) 'will remove the rec[20][3] element. (a single integer) 'so, rec[20] is an Integer[] with 9 (not 10) elements: [0]...[8] rec[46] = rec[45] 'The Integer array at rec[46] pointed to is gone. Poof! Vaporized. 'rec[46] doesn't point to it anymore. 'rec[45] and rec[46] point to the same identical integer[] array 'which originally was created as rec[45] 'Then, if you wrote rec.delete(45), the array would not be gone because 'rec[46] still points to ithowever, the .delete moves everything 'down one element: rec[46]..[99] is now rec[45]..[98] Swap rec[40], rec[41] 'the whole integer[] arrays 40 and 41 are swapped. 'data is not copied, just the pointer to the arrays are. ' ..something else... Dim s as String[] s = New String[] rec.add(s,92) 'rec[0..91] each are an Integer[10] array 'rec[92] is a String[] array with 0 elements. 'rec[93..100] each are an Integer[10] array rec[92].add(HELLO) 'rec[92] is now a String[] array with 1 element... 'which is: rec[92][0] = HELLO ' ..some where else... ' I want an array of 500 Labels in rec[50] Dim L as Label Dim i as Integer Dim o as New Object[500] 'declare AND create a new Object[] array with 500 elements rec[50].add(o) 'rec[50] Integer[] is now rec[51]. Everything bumped up one [] For i = 0 To 499 '...and rec[50] is an Object[500] L = New Label 'create a New Label rec[50][i] = L 'now rec[50][i] points to the new label Next 'Every one of the 500 Labels in rec[50] are created and unique '..and you could display each of them on a Form. '- It can get quite interesting because this works with any objects including GUI Labels, Timers, Strings, Structs, Panels, and so on. (when doing GUI things, you also have to connect them to event handlers too ...I didn't write that here) The most important part is to understand the difference about DECLARING variable names (for the program to compile) (using DIM or Private or Public) and CREATING new variables at run-time. (like ...As NEW Object[500] ...As NEW Label) I'm pretty sure I got the syntax right. -Nando -- Original Message --- From: Kevin Fishburne kevinfishbu...@eightvirtues.com To: mailing list for gambas users gambas-user@lists.sourceforge.net Sent: Wed, 19 Aug 2015 02:22:54 -0400 Subject: [Gambas-user] Multidimensional dynamic array basics I need to know how to declare, initialize and add elements to a two-dimensional dynamic array. Using trial-and-error for every possible syntax hasn't been too helpful so far. I'd post my code but it's pretty useless and embarrassing and I think the basic question sums it up. -- Kevin Fishburne Eight Virtues www: http://sales.eightvirtues.com e-mail: sa...@eightvirtues.com phone: (770) 853-6271 -- ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user --- End of Original Message --- -- ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user
Re: [Gambas-user] Multidimensional dynamic array basics
Hello Kevin, I'm on vacation and I'm not sure I understand the question, I am attaching this example in Italian perhaps with Google Translator can help. Regards Gianluigi 2015-08-19 8:22 GMT+02:00 Kevin Fishburne kevinfishbu...@eightvirtues.com: I need to know how to declare, initialize and add elements to a two-dimensional dynamic array. Using trial-and-error for every possible syntax hasn't been too helpful so far. I'd post my code but it's pretty useless and embarrassing and I think the basic question sums it up. -- Kevin Fishburne Eight Virtues www: http://sales.eightvirtues.com e-mail: sa...@eightvirtues.com phone: (770) 853-6271 -- ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user StudioMatriceBidimensionaleLibera-0.0.2.tar.gz Description: GNU Zip compressed data -- ___ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user