'
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'1、新建一个工程;
'2、在窗体Form1内放入Label1、Timer1、Command1、Command2四个控件;
'3、把以下代码直接复制到你的工程里;
'4、在工程所在的文件夹里新建一个文本文件“N.txt”,把名字写入文件,一行一个名字。
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
''
'《小小程序员》
'Ant 2011.6.25深夜有感
'
'代码虽简单,
'为你解忧烦,
'写码伤脑筋,
'占用我一晚;
'每每向钱看,
'钱包总受伤,
'拷完顶一顶,
'就算帮个忙。
'
Option Explicit
Dim TempAs String
DimNameTxt(5000) AsString '存储从“N.txt”中逐行读取的内容,如果大于5000条记录请更改为更大的数字。
Dim i AsLong
Dim Lc AsLong 'N.txt中的记录总数(文本行数)
Dim x AsLong ' 存储随机数
Private Sub Command1_Click()
i = 0
Lc = 0
x =999999
OpenApp.Path & "N.txt" For Input As#1 '数一数“N.txt”中有几个记录。
Do While NotEOF(1)
Line Input #1, Temp
Lc = Lc + 1
NameTxt(Lc) =Temp '把记录写入数组。
Loop
Close#1
IfTimer1.Enabled = FalseThen '控制定时器。
Timer1.Enabled = True
Else
Timer1.Enabled = False
End If
Command2.Enabled = True
Command1.Enabled = False
End Sub
Private Sub Command2_Click()
Randomize '产生记录总数以内的随机数x
x = Int((Lc-1 + 1) * Rnd + 1)
Command2.Enabled = False
End Sub
Private Sub Form_Load()
Timer1.Interval =100 '改变数字100可以调整滚动速度。
Timer1.Enabled = False
Command2.Enabled = False
Me.Caption ="随机点名"
Command1.Caption = "开始滚动"
Command2.Caption = "停"
Label1.Caption = "名单已准备好"
End Sub
Private Sub Timer1_Timer()
i = i +1
Label1.Caption = i & " "& NameTxt(i) '显示记录
If i = xThen '当滚动随机数x这条记录时停止
i = 0
Command1.Enabled = True
Timer1.Enabled = False
Else
If i = Lc Then i = 0
End If
End Sub