为什么点击停止时会执行CmdStop_Click()
这是一列出下级所有目录VB源码,为什么点击停止时会执行CmdStop_Click(),是哪里设置的Option Explicit
Private Sub CmdStart_Click()
Static running As Boolean
Dim AllDirs As New Collection
Dim next_dir As Integer
Dim dir_name As String
Dim sub_dir As String
Dim i As Integer
Dim txt As String
If running Then
running = False
CmdStart.Enabled = False
CmdStart.Caption = "Stopping"
Else
running = True
MousePointer = vbHourglass
CmdStart.Caption = "Stop"
OutText.Text = ""
DoEvents
next_dir = 1
AllDirs.Add StartText.Text ' 开始
Do While next_dir <= AllDirs.Count
' 获得下一个子目录
dir_name = AllDirs(next_dir)
next_dir = next_dir + 1
' 从 dir_name 读路径
sub_dir = Dir$(dir_name & "\*", vbDirectory)
Do While sub_dir <> ""
' 添加路径名称到列表
' 它是一个路径
If UCase$(sub_dir) <> "PAGEFILE.SYS" And _
sub_dir <> "." And sub_dir <> ".." _
Then
sub_dir = dir_name & "\" & sub_dir
On Error Resume Next
If GetAttr(sub_dir) And vbDirectory _
Then AllDirs.Add sub_dir
End If
sub_dir = Dir$(, vbDirectory)
Loop
DoEvents
If Not running Then Exit Do
Loop
' 更新显示
txt = ""
For i = 1 To AllDirs.Count
txt = txt & AllDirs(i) & vbCrLf
Next i
OutText.Text = txt
MousePointer = vbDefault
CmdStart.Caption = "Start"
CmdStart.Enabled = True
running = False
End If
End Sub
Static running As Boolean
Dim AllDirs As New Collection
Dim next_dir As Integer
Dim dir_name As String
Dim sub_dir As String
Dim i As Integer
Dim txt As String
If running Then
running = False
CmdStart.Enabled = False
CmdStart.Caption = "Stopping"
Else
running = True
MousePointer = vbHourglass
CmdStart.Caption = "Stop"
OutText.Text = ""
DoEvents
next_dir = 1
AllDirs.Add StartText.Text ' 开始
Do While next_dir <= AllDirs.Count
' 获得下一个子目录
dir_name = AllDirs(next_dir)
next_dir = next_dir + 1
' 从 dir_name 读路径
sub_dir = Dir$(dir_name & "\*", vbDirectory)
Do While sub_dir <> ""
' 添加路径名称到列表
' 它是一个路径
If UCase$(sub_dir) <> "PAGEFILE.SYS" And _
sub_dir <> "." And sub_dir <> ".." _
Then
sub_dir = dir_name & "\" & sub_dir
On Error Resume Next
If GetAttr(sub_dir) And vbDirectory _
Then AllDirs.Add sub_dir
End If
sub_dir = Dir$(, vbDirectory)
Loop
DoEvents
If Not running Then Exit Do
Loop
' 更新显示
txt = ""
For i = 1 To AllDirs.Count
txt = txt & AllDirs(i) & vbCrLf
Next i
OutText.Text = txt
MousePointer = vbDefault
CmdStart.Caption = "Start"
CmdStart.Enabled = True
running = False
End If
End Sub
Private Sub CmdStop_Click()
CmdStart.Enabled = False
CmdStop.Enabled = False
running = False
End Sub
CmdStart.Enabled = False
CmdStop.Enabled = False
running = False
End Sub
[[italic] 本帖最后由 烟雨袅袅 于 2007-12-10 05:36 编辑 [/italic]]
列出所有下级目录.rar
(2.64 KB)