1,065
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Private fso As New FileSystemObject
Private mcolNames As New Collection
Private mintIndex As Integer
Private Property Get File1Path() As String
File1Path = fso.BuildPath(App.Path, "1.txt")
End Property
Private Property Get File2Path() As String
File2Path = fso.BuildPath(App.Path, "2.txt")
End Property
Private Sub cmdReset_Click()
Dim objStream As TextStream
Set objStream = fso.OpenTextFile(File2Path, ForWriting, True)
objStream.Close
End Sub
Private Sub cmdStart_Click()
Dim i As Long
For i = 1 To mcolNames.Count
mcolNames.Remove 1
Next
Dim objStream As TextStream
Set objStream = fso.OpenTextFile(File1Path, ForReading, False)
While Not objStream.AtEndOfStream
Dim strName As String
strName = objStream.ReadLine()
mcolNames.Add strName
Wend
objStream.Close
Set objStream = fso.OpenTextFile(File2Path, ForReading, False)
While Not objStream.AtEndOfStream
strName = objStream.ReadLine()
For i = mcolNames.Count To 1 Step -1
If mcolNames(i) = strName Then
mcolNames.Remove i
Exit For
End If
Next
Wend
objStream.Close
If mcolNames.Count > 0 Then
Timer1.Enabled = True
Else
MsgBox "已经全部抽取了!", vbExclamation
End If
End Sub
Private Sub cmdStop_Click()
Timer1.Enabled = False
Dim objStream As TextStream
Set objStream = fso.OpenTextFile(File2Path, ForAppending, True)
objStream.WriteLine mcolNames(mintIndex)
objStream.Close
End Sub
Private Function GetRandomNumber(ByVal intStart As Integer, ByVal intEnd As Integer) As Integer
GetRandomNumber = Int(Rnd * (intEnd - intStart + 1) + intStart)
End Function
Private Sub Form_Load()
Randomize
Timer1.Enabled = False
Timer1.Interval = 20
End Sub
Private Sub Timer1_Timer()
mintIndex = GetRandomNumber(1, mcolNames.Count)
Label1.Caption = mcolNames(mintIndex)
End Sub