简体   繁体   中英

Using a Variant Array in a loop (error 13 type mismatch)

I'm doing a for loop and need to use a Variant Array type, but i'm getting Error 13 (type mismatch). I want k to be 3, 4 and 5 for the 1st value, and so on (according to variable inspection below). I just don't know how to make vba read the array. I've tried using tsperiodo(i)(j) but it hasn't worked either.

Here is the variant array:

ReDim ocup(1 To numDis, 1 To numSalas) As Variant

For i = 1 To numDis
    For j = 1 To numSalas
        If capacidadeSalas(j) - alunos(i) >= 0 Then
        ocup(i, j) = 1
        End If
    Next
Next    

ReDim tsPeriodo(1 To numDis) As Variant

For i = 1 To numDis
    tsPeriodo(i) = Application.Transpose(Evaluate("=ROW(" & tsInicio(i) & ":" & tsFim(i) & ")"))
Next

and here is where i want to use it:

For i = 1 To ocup(numDis, 1)
    For j = 1 To ocup(1, numSalas)
        For k = 1 To tsPeriodo(i)  'this is where im getting error 13
            variable = "x_" & i & "_" & j & "_" & k
        Next
    Next
Next

variable inspection for the tsperiodo(i)

Without understanding deeply what you are trying to achieve, obviously each element of tsPeriodo is an variant/array itself, so you end up with some kind of a (non-standard) 2D array. To catch all the elements inside it in your loop, you can try this:

Dim k, l
For Each k In tsPeriodo
    For Each l In k
      ' doSomething, i.e.
      variable = "x_" & i & "_" & j & "_" & l

    Next
Next

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM