即使对于我来说,VBA骰子卷也是非常容易的事情,但我需要特定的类型,当卷6意味着您可以再次滚动并将两个卷添加在一起(加上当您连续两次滚动6次,你得到第三轮等等)。VBA骰子卷加
我已经尝试了两种方法,但都失败了
Sub roll_dice_1()
Dim result As Range
Set result = Range("A1")
result = Application.WorksheetFunction.RandBetween(1, 6)
If result = 6 Then
result = result + Application.WorksheetFunction.RandBetween(1, 6)
Do Until Application.WorksheetFunction.RandBetween(1, 6) <> 6
result = result + Application.WorksheetFunction.RandBetween(1, 6)
Loop
Else
End If
End Sub
然而,这一个可以产生12结果,这显然是不可能的,因为两次6应该给第三卷
Sub roll_dice_2()
Dim result As Range
Set result = Range("A1")
result = Application.WorksheetFunction.RandBetween(1, 6)
If result = 6 Then
Do Until Application.WorksheetFunction.RandBetween(1, 6) <> 6
result = result + Application.WorksheetFunction.RandBetween(1, 6)
Loop
Else
End If
End Sub
这一个工作更糟糕,因为它可以返回6.
我尝试搜索高低,但我所得到的只是简单的代码简单的投掷,与两个骰子和卷当某些结果可以重新投放时。再次,所有的选项都很容易,不像这一个
谢谢,我知道环路错误是这样的,但我的想法如何使它工作 – telesien
BTW有你为什么宣布结果并滚动长,当整数应该以任何理由足够? – telesien
在这种情况下可能是一种很差的习惯。我习惯于使用它来避免溢出错误,但是在这种情况下你不会冒这个问题。所以你是对的。已更正 – Tom