Private Sub Command1_Click()
Dim N As Integer, MaxLine As Integer
Randomize
MaxLine = 1000 '总行数
N = Int(Rnd * MaxLine) + 1 '随机生成一个数
Open "c:\tt.txt" For Input As #1
i = 0
Do While Not EOF(1)
i = i + 1
Line Input #1, S
If i = N Then '取得这一行
Exit Do
End If
Loop
Close #1 '加上这一句就OK了
Label1.Caption = S
'注,如果总行数没有这么多行,产生的随机数又大于这个数,则会取得最后一行
End Sub
上面的代码,是我疏忽大意,忘了关闭文件了
温馨提示:答案为网友推荐,仅供参考