用vb制作随机点名器,提供代码及详细制作步骤
1.Form的Caption属性可命名为:课堂随机点名
2.在界面放入一个Listbox, 一个Label ,一个commandbotton,它们的属性不用改变。
3.右击表单Form,选择“查看代码”
4.输入下列代码:
Option Explicit
Dim flag As Boolean
Private Sub Command1_Click()
With Command1
If .Caption = "点名" Then
.Caption = "停止"
flag = False
test
Else
.Caption = "点名"
flag = True
End If
End With
End Sub
Function test()
Dim t
Do Until flag
Label1.Caption = List1.List(Int(Rnd * List1.ListCount)) t = Timer
Do Until Timer - t > 0.05
DoEvents
Loop
DoEvents
Loop
End Function
Private Sub Form_Load()
Dim arr, i As Integer
List1.Visible = False
Command1.Caption = "点名"
With Label1
.Caption = ""
.AutoSize = True
.ForeColor = vbRed
.FontSize = 24
.FontBold = True
End With
Open App.Path & "\123.txt" For Input As #1 (备注说明:在保存位置同一目录下新建一个123的文本文件,并把名单录入到文本中,一个名字一行。)
Close #1
For i = 0 To UBound(arr)
If Len(arr(i)) > 0 Then List1.AddItem arr(i)
End Sub
运行界面如下: