[Gambas-user] Dim two-dimensional dynamic array

Dag Jarle Nerland Johansen - Gambas gambas at cd-bahia.com
Sun Sep 5 13:00:55 CEST 2021


Am 02.09.21 um 16:34 schrieb Benoît Minisini:
> Le 02/09/2021 à 14:49, Tobias Boege via User a écrit :
>> On Thu, 02 Sep 2021, Dag Jarle Nerland Johansen - Gambas wrote:
>>> Hi,
>>> I didn't find how to declare a dynamic two-diemnsional array.
>>> One-dimension I make like this:
>>> Public arr As New String[]
>>> and then simply use the add-method.
>>>
>>> I see two-dimensions are declared like this
>>> Dim arr As New String[3, 8]
>>>
>>> I want to read in MySQL records in the arrays, because I repeat the 
>>> use of
>>> them during the process of generating form and class, and that takes 
>>> too
>>> much time, the programm got slow. And as I dont know how many 
>>> records I get,
>>> I need it dynamicly. The same is for the amount of fields, different 
>>> tables.
>>>
>>
>> In Gambas you can always create an array containing objects of type T
>> by doing
>>
>>    Dim a As New T[]
>>
>> Now, to get a two-dimensional array, make an array of arrays:
>>
>>    Dim a As New T[][]
>>
>> You access one object via a[i][j] (_not_ via a[i,j]). And of course
>> you can add new rows to a and new columns to a given row a[i] as you
>> normally do with arrays.
>>
>> Best,
>> Tobias
>>
>
> For storing the contents of an SQL table, it's better and faster to do:
>
> Dim aData As String[]
>
> ...
>
> aData = New String[NumberOfRows, NumberOfFields]
>
> Regards,
>
Hi again.
Benoit's way worked best for me. I got a little confused in how to 
address an array, I have to read more about arrays. For me arrays always 
have simply been a list of elements, here an array seems to have an 
exended meaning. Anyhow, thanks to all.
Regards, Dah JNJ


More information about the User mailing list