[Gambas-user] Dim two-dimensional dynamic array

Benoît Minisini g4mba5 at gmail.com
Thu Sep 2 16:34:42 CEST 2021


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,

-- 
Benoît Minisini


More information about the User mailing list