Os comento este problema.
Si tengo un array tal como este: [1,2,3,4,[5,6,7] ]
¿ Cómo harías para visualizar cada elemento del array ?.
Lo hice de esta forma:
Public Sub Main()
Dim alista1 As Variant[] = [1, 2, 3, 4]
alista1.Add([5, 6, 7])
MostrarArray(alista1)
End
Public Sub MostrarArray(lista As Variant[])
Dim tipo1 As Variant
Dim tipo2 As Integer
For Each tipo1 In lista
If TypeOf(tipo1) = gb.Integer Then
Print tipo1
'Llega un momento que tipo1 es un array
Else If TypeOf(tipo1) = gb.Object Then
For Each tipo2 In tipo1
Print tipo2
Next
Endif
Next
End
Dim alista1 As Variant[] = [1, 2, 3, 4]
alista1.Add([5, 6, 7])
MostrarArray(alista1)
End
Public Sub MostrarArray(lista As Variant[])
Dim tipo1 As Variant
Dim tipo2 As Integer
For Each tipo1 In lista
If TypeOf(tipo1) = gb.Integer Then
Print tipo1
'Llega un momento que tipo1 es un array
Else If TypeOf(tipo1) = gb.Object Then
For Each tipo2 In tipo1
Print tipo2
Next
Endif
Next
End
El tipo Objeto es como un comodín. No hay un tipo Array.
¿ Cómo lo harías vosotros ?.
Bien, vayamos a otra cuestión.
¿ Como es que siendo Variant no puedo hacer algo como esto ?.
lista1 = [1,2,3,4]
lista2 = [5,6,7]
lista1[2] = lista2
Según el error es las dimensiones están definidas.
Es fácil añadir, pero no sustituir. Puedo añadir un array a un array con el método .add, pero no puedo asignar a un elemento que parece de una dimensión, otro de mas dimensiones.
Saludos