Этот код раньше работал, но недавно я получаю сообщение об ошибке (недостаточно места в стеке).
Я думаю, что код не работает, потому что я вызываю функцию слишком много раз без выхода / завершения.
Если это так, сколько раз вы можете вызывать функцию и могу ли я что-то сделать, чтобы это исправить?
Я не являюсь первоначальным автором этого кода.
Я включил саб, где происходит ошибка.
Sub CalculatePct(e As Variant)
Dim G As Integer
Dim pct As Double
Dim Owned100Pct As Boolean
If entities(e) < 0 Then
pct = 0
Owned100Pct = True ' Keeps track if the entity exists in the table other than as a parent
For G = 1 To UBound(MainArray, 1)
If MainArray(G, colEntity) = e Then
Owned100Pct = False
If entities(MainArray(G, colParent)) = -1 Then
'If we don't know the parent's ownership percentage, go and calculate it
CalculatePct MainArray(G, colParent)
End If
pct = pct + CDbl(MainArray(G, colPct)) / 100 * entities(MainArray(G, colParent))
End If
Next
If Owned100Pct Then
'Assume 100% owned if we don't know the parentage
'("Outside" entities won't go through here as they are already set to 0%)
entities(e) = 1
Else
'Store the entity's percentage
entities(e) = pct
End If
End If
End Sub