Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Debugging 为什么生成的随机数不存储在变量中_Debugging_Excel_Vba - Fatal编程技术网

Debugging 为什么生成的随机数不存储在变量中

Debugging 为什么生成的随机数不存储在变量中,debugging,excel,vba,Debugging,Excel,Vba,这是我的密码 Sub lab1() Dim first As Integer Dim third As Integer Dim total As Integer total = 0 For i = 0 To i = 99 first = Application.WorksheetFunction.RandBetween(1, 100) total = total + first Next i MsgBox (total) End Sub 我试图生成100个介于1到10

这是我的密码

Sub lab1()

Dim first As Integer
Dim third As Integer
Dim total As Integer

total = 0

For i = 0 To i = 99
    first = Application.WorksheetFunction.RandBetween(1, 100)
    total = total + first
Next i

MsgBox (total)

End Sub

我试图生成100个介于1到100之间的随机数,并将每个数存储到变量“total”中。我不明白为什么total的值总是低于100,似乎“total”只存储了1个随机数,而不是100个随机数,因为I=0到99VBA在
之后需要一个数字,所以I=0到I=99的
行被解释为
对于I=0到(I=99)
,由于刚刚用值
0
创建了
i
,表达式
i=99
等于
False
,布尔值
False
转换为
0


因此,i=0到i=99的
行被解释为i=0到0的

我不明白你的意思,我的代码和你的代码有什么区别??对于i=0到99,对于i=0到i=99,请检查你的代码。我注意到您的语法有一个错误。@joseph请告诉我哪一行,我对VBA编程一无所知
Dim first As Integer
    Dim third As Integer

    Dim total As Integer


    total = 0

    For i = 0 To 99


    first = Application.WorksheetFunction.RandBetween(1, 100)



    total = total + first

    Next i

    MsgBox (total)