[Gambas-user] Arrays of mixed numeric type always float[] not variant[]

T Lee Davidson t.lee.davidson at gmail.com
Tue Mar 8 19:32:12 CET 2022


On 3/7/22 14:28, Brian G wrote:
> When I create an array
> 
> dim a = [1, 2, 3, 4, 4.5]
> Gambas always creates a float[] not variant[], which makes it impossible to add sets like [1,3,4] to the array later.  Is this 
> the correct
> behavior for mixed arrays of numbers?

Is there a reason you can't declare the array as Variant[]? I don't have any problem inserting an integer array into a variant 
array.

This code:
Public Sub Main()

   Dim a As Variant[] = [1, 2, 3, 4.5, 5]

   a.Insert([6, 7, 8])
   For Each b As Variant In a
     Print b & "\t" & TypeOf(b)
   Next

End

Yields:
1       7
2       7
3       7
4.5     7
5       7
6       4
7       4
8       4


-- 
Lee


More information about the User mailing list