在本程序中,同学的学号、姓名信息均来自 初一五班选修课志愿表
Dim MyValue As
Integer
Dim last As
Integer
Dim counter As
Long '注:使用long定义了计数器,则启动一次不进行重置,最多可生成(2^31-1+1)个随机数,在原基础上+1是因为初值为0
Private Sub
make_Click()
If counter =
0 Then '注:计数器为初值0,即程序第一次生产随机数时,运行下面语句
Randomize
MyValue =
Int((39 * Rnd()) + 1)
last =
MyValue
counter =
counter + 1
GoTo
changetoname
End
If
If counter
>= 1 Then '注:当程序第二次或更多次生成随机数时,运行下面语句
Randomize
MyValue =
Int((39 * Rnd()) + 1)
If MyValue =
last Then GoTo redo
'注:如果本次产生的随机值等于上一次的随机值,则跳转到redo部分,重新生成随机数。
last =
MyValue
counter =
counter + 1
GoTo
changetoname
End
If
redo:
Randomize
MyValue =
Int((39 * Rnd()) + 1)
If MyValue =
last Then GoTo redo
last =
MyValue
counter =
counter + 1
GoTo
changetoname
changetoname:
If MyValue =
1 Then
final.Caption = "01 王金戈"
End