I am struggling slightly with my indexing of my array. I want the upper bound of the array to be the amount of time's the Function RandomizeDice() executes. Any help is greatly appreciated.
Function RandomizeDice()
RandomizeDice = Application.WorksheetFunction.RandBetween(1, 6)
End Function
Sub RollDice()
Dim DiceOne() As Variant
Dim DiceTwo() As Variant
Dim SumDice() As Variant
Dim i As Integer
ReDim DiceOne(i) As Variant
ReDim DiceTwo(i) As Variant
ReDim SumDice(i) As Variant
Call arraySet(DiceOne(), DiceTwo(), SumDice())
Debug.Print SumDice(i)
'Debug.Print SumDice(0)
' Debug.Print ("Dice: " & DiceOne(0) & " " & DiceTwo(0))
' Debug.Print ("Sum: " & DiceOne(0) + DiceTwo(0))
End Sub
Sub arraySet(ByRef a() As Variant, b() As Variant, c() As Variant)
'Dim DiceOne() As Integer
'Dim DiceTwo() As Integer
Dim i, j As Integer
'Dim intSumDice() As Integer
For i = 0 To j = i + 1
a(i) = RandomizeDice() 'dice1
b(i) = RandomizeDice() 'dice2
c(i) = a(i) + b(i) 'sum
Next i
Debug.Print i
Debug.Print ("Dice: " & a(0) & " " & b(0))
Debug.Print ("Sum: " & a(0) + b(0))
End Sub
Bookmarks