[Gambas-user] Matrix resize

Fabien Bodard gambas.fr at ...626...
Thu Dec 5 17:54:25 CET 2013


You can use arrays of array


private MyArray as new Object[]

Public sub _New()
ResizeMyArray(MyArray,15,12)
end



Public sub ResizeMyArray(hMyArray as Object[], X as integer, y as integer)

hMyArray.Resize(X)

For i = 0 to hMyArray.max
  if hMyArray [i] then
  hMyArray[i].Resize(y)
  else
  hMyArray[i] = new Integer[Y]
  endif
next



For the call :

value = MyArray[1][2]


2013/12/5 Jussi Lahtinen <jussi.lahtinen at ...626...>:
> Unfortunately this is missing feature from Gambas. Maybe Benoit has reason
> for it, I don't know.
>
> However here is code for resizing 2D arrays:
>
> Private Function Resize2DArray(hArray As Object, SizeX As Integer, SizeY As
> Integer) As Object
>
>   Dim hNewArray As Object = Object.New(Object.Type(hArray), [SizeX, SizeY])
>   Dim ii As Integer, jj As Integer
>
>   For ii = 0 To Min(hNewArray.Bounds[0], hArray.Bounds[0]) - 1
>   For jj = 0 To Min(hNewArray.Bounds[1], hArray.Bounds[1]) - 1
>     hNewArray[ii, jj] = hArray[ii, jj]
>   Next
>   Next
>
>   Return hNewArray
>
> End
>
>
> And here is how to use it:
>
> Dim iMyArray As New Integer[5, 5]
>
> iMyArray = Resize2DArray(iMyArray, 10, 10)
>
>
> As it's not native method, it's not that fast, but fortunately Gambas is
> *very* often fast enough!
>
>
> Jussi
>
>
>
> On Thu, Dec 5, 2013 at 2:20 PM, terco IDE <tercoide at ...67...> wrote:
>
>> First of everything: BIG thanks to Benoit for crating Gambas!
>>
>> Is there any workaround for resizing matrices?
>>
>> rigth now, I'm using this code
>>
>> notMatrix.Resize(100*200)  ' 100 rows, 200 cols
>>
>> ' get element [row,col]
>>
>> x = notMatrix[col + row*200]
>>
>> , and on a big program, code get's really dirty
>>
>>
>> Thanks!
>>
>>
>> Saludos
>> Martin
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Sponsored by Intel(R) XDK
>> Develop, test and display web and hybrid apps with a single code base.
>> Download it for free now!
>>
>> http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk
>> _______________________________________________
>> Gambas-user mailing list
>> Gambas-user at lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
> ------------------------------------------------------------------------------
> Sponsored by Intel(R) XDK
> Develop, test and display web and hybrid apps with a single code base.
> Download it for free now!
> http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user



-- 
Fabien Bodard




More information about the User mailing list