'窗体上分别放驱动器列表框,目录列表框,文件列表框 Option ExplicitPrivate Sub Dir1_Change() File1.Path = Dir1.Path End SubPrivate Sub Drive1_Change() Dir1.Path = Drive1 End SubPrivate Sub Form_Load() Dim i As Integer For i = 0 To File1.ListCount - 1 If InStr(1, File1.List(i), "ABC") > 0 Then File1.Selected(i) = True End If Next End Sub
Dim i As Integer For i = 0 To File1.ListCount - 1 If Trim(File1.List(i)) = "ABC" Then File1.Selected(i) = True Exit For 'Else '其他操作 End If Next End Sub
Option ExplicitPrivate Sub Dir1_Change()
File1.Path = Dir1.Path
End SubPrivate Sub Drive1_Change()
Dir1.Path = Drive1
End SubPrivate Sub Form_Load()
Dim i As Integer
For i = 0 To File1.ListCount - 1
If InStr(1, File1.List(i), "ABC") > 0 Then
File1.Selected(i) = True
End If
Next
End Sub
Option ExplicitPrivate Sub Form_Load()
'File1是文件列表框
File1.AddItem "sagag"
File1.AddItem "ABC"
File1.AddItem "ghg"
File1.AddItem "jajgopk"
File1.AddItem "agaga"
Dim i As Integer
For i = 0 To File1.ListCount - 1
If Trim(File1.List(i)) = "ABC" Then
File1.Selected(i) = True
Exit For
'Else
'其他操作
End If
Next
End Sub