[Gambas-user] Way to create dynamic Arrays

Jussi Lahtinen jussi.lahtinen at gmail.com
Tue Aug 15 23:04:36 CEST 2023


Probably better use Integer instead of Short for the array index. There is
no gains in using Short here, but you can, in some cases, avoid bug from
possible overflow with Integer.
The max for Short is 32767 and because it is an array of Shorts it may be
so, because it is very big.

Jussi

On Tue, Aug 15, 2023 at 11:45 PM Gianluigi <gradobag at gradobag.it> wrote:

> Il 15/08/23 22:03, Jussi Lahtinen ha scritto:
>
> Next time it is better to attach a small project to illustrate your
> problem. Many times (like this one) the problem is not in the given code.
> However, you should not use "Samples" as variable name twice, once for
> public and once for the local.
>
> Jussi
>
> On Tue, Aug 15, 2023 at 10:47 PM Hartmut Wagener <
> hartmut.w.wagener at t-online.de> wrote:
>
>> I have tried the dynamic arrays.
>>
>> I created an array
>>
>>
>> Public Samples as Short[]
>>
>>
>> Inside the program i used
>>
>>
>> Dim Samples As New Short[countSamples]
>>
>>
>> to add an array-entry.
>>
>>
>> countSamples is incremented each new Sample.
>>
>>
>> The program runs through the readin-phase, but there is no array created
>> with all the samples.
>>
>>
>> What is wrong?
>>
>>
>> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>>
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
> Can this help?
>
> '----------------------
>
> Public Sub Main()
>
>   Dim countSamples As Short = 10
>   Dim Samples As New Short[countSamples]
>
>   For s As Short = 0 To countSamples - 1
>     Samples[s] = s
>     Print Samples[s]
>   Next
>   Samples.Clear
>   Print "--"
>   For s = 0 To countSamples + 10
>     Samples.Push(s)
>     Print Samples[s]
>   Next
>
> End
> '-------------------
>
> Regards
>
> Gianluigi
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230816/6eaa2198/attachment-0001.htm>


More information about the User mailing list