If Timer1.Enabled = True Then
Timer1.Enabled = False
MsgBox List1.Text &" " &List2.TextElse
List1.ListIndex = Int(Rnd() * 24)
List2.ListIndex = List1.ListIndex
Timer1.Interval = 100
Timer1.Enabled = True
End If
End SubPrivate Sub Form_Load()
'加测试数据
For i = 1 To 24
List1.AddItem Chr(i + 64)
List2.AddItem iNext
End SubPrivate Sub Timer1_Timer()
If List1.ListIndex = List1.ListCount - 1 Then
List1.ListIndex = 0
Else
List1.ListIndex = List1.ListIndex + 1
End If
List2.ListIndex = List1.ListIndex
End Sub
这个程序的重点就是读Excel表格,如果能读出来人员名单,下面就用随机数就很好写了
我测试代码
Dim ExcelApp As Object
Dim ExcelBook As Object
Dim ExcelSheet As Object
Dim n As Long
Set ExcelApp = CreateObject("Excel.Application")
Set ExcelBook = ExcelApp.Workbooks.Open("c:\0.xls")
Set ExcelSheet = ExcelBook.Worksheets(1)
n = 1
Do
List1.AddItem ExcelSheet.Range("D" &n).Value
n = n + 1
Loop Until ExcelSheet.Range("D" &n).Value = ""
Set ExcelSheet = Nothing
Set ExcelBook = Nothing
Set ExcelApp = Nothing
我的人员名称是在D列,同理,如果还想要其它列(学号),在后后加上就行了
为了 *** 作excel,还引用了"Microsoft Excel 11.0 Object Library"对像
建一个COmmand1。模式如下。
=============
Option Base 1
Dim a, i As Integer
Private Sub Command1_Click()
i = Int(Rnd * 8 + 1)
MsgBox i &" " &a(i)
End Sub
Private Sub Form_Load()
Randomize
a = Array("赵", "钱", "孙", "李", "周", "吴", "郑", "王")
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)