我有下面的代码查找组合框中显示的值,然后使用与所选扩展名相关的所选文件名填充列表框(也许代码会更有意义!)
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim lyxfle As New IO.DirectoryInfo(sPath)
Dim diar1 As IO.FileInfo() = lyxfle.GetFiles()
Dim MyExt As String = Nothing
Dim MyVariable As String
Dim sFile As String
MyVariable = ComboBox1.Text
If MyVariable = "Forms" Then MyExt = "*.pff"
If MyVariable = "Reports" Then MyExt = "*.mdb"
If MyVariable = "Spreadsheets" Then MyExt = "*.xlsm"
ListBox2.Items.Clear()
sFile = Dir$(sPath & MyExt)
Do While CBool(Len(sFile))
ListBox2.Items.Add(System.IO.Path.GetFileNameWithoutExtension(sFile))
sFile = Dir$()
Loop
End Sub
以下是我正在努力解决的问题
If MyVariable = "Spreadsheets" Then MyExt = "*.xlsm"
我基本上还需要它来查看扩展名 .xls 和 .xlsx 并在列表中包含所有文件
Path 和 sPath 都在类的顶部声明为私有字符串
任何建议