Hallo Otto5891
So sollte es funktionieren:
Sub
test()
Dim
Anzahl_der_Wuerfel
As
Integer
Dim
wuerfel()
As
Integer
Dim
werte()
As
Integer
Anzahl_der_Wuerfel =
CInt
(InputBox(
"Wie viele Wuerfel? "
))
ReDim
wuerfel(Anzahl_der_Wuerfel - 1)
ReDim
werte(Anzahl_der_Wuerfel - 1)
Range(
"A1"
).
Select
For
i = 0
To
Anzahl_der_Wuerfel - 2
werte(i) = 1
Next
i
wuerfeln Anzahl_der_Wuerfel - 1, werte
End
Sub
Public
Function
GetWert(werte)
As
Integer
For
idx = LBound(werte)
To
UBound(werte)
GetWert = GetWert + werte(idx)
Next
idx
End
Function
Public
Sub
wuerfeln(actidx, werte)
Dim
nw
As
Integer
werte(actidx) = werte(actidx) + 1
If
LevelUp(actidx, werte)
Then
Exit
Sub
ActiveCell.FormulaArray = (GetWert(werte))
ActiveCell.Offset(1, 0).
Select
wuerfeln actidx, werte
End
Sub
Public
Function
LevelUp(actidx, werte)
As
Boolean
Dim
nw
As
Integer
LevelUp =
False
If
werte(actidx) > 6
Then
werte(actidx) = 1
nw = actidx - 1
If
nw < 0
Then
LevelUp =
True
Else
werte(nw) = werte(nw) + 1
LevelUp = LevelUp(nw, werte)
End
If
End
If
End
Function