小编Cry*_*ork的帖子

比较数组中的数字

所以这个问题比简单的比较更深入.基本上我试图模拟这个骰子卷,称为滚动和保持系统.例子是5k3.在哪里我会掷5个骰子并保持3个最高,然后将它们加在一起.

我已经得到了我的小宏程序来掷骰子.然后我将它们放在我的示例中的数组中,该数组将是一个包含5个索引的数组.现在我需要拿这5个骰子,并且只保留其中最大的3个.

代码在这里A2给了我骰子的数量,B2给了我多少我滚动,C2给了我多少我保持.这会掷10个骰子,但随后我将其中的5个转移到我的实际骰子中.我知道我可以跳过这个,但我可以稍后处理.

Private Sub CommandButton1_Click()

Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim RandNum As Integer
Dim RollArray() As Integer
Dim KeptArray() As Integer
Dim RollArrayDummy() As Integer
Dim NumRoll As Integer
Dim Kept As Integer
Dim Largest As Integer

NumRoll = Range("B2").Value
ReDim RollArray(NumRoll)

Kept = Range("C2").Value
ReDim KeptArray(Kept)

For i = 5 To 15
Randomize

    RandNum = 1 + Rnd() * (Range("A2").Value - 1)
    Cells(i, 1).Value = RandNum
Next i

For j …
Run Code Online (Sandbox Code Playgroud)

excel vba excel-vba

6
推荐指数
1
解决办法
96
查看次数

标签 统计

excel ×1

excel-vba ×1

vba ×1