如何打开指定目录中提取所有图片的文件名放到listbox控件中去?
做这个例子,我不知道该怎么写才正确??Private Sub Command1_Click()
Dim arr
Dim StrText As String
'On Error GoTo Note '当出现错误时,跳转到Note语句
With CommonDialog1
.DialogTitle = "打开对话框"
.Filter = "图片文档(*.jpg) |*.jpg|图片文档(*.bmp) |*.bmp"
.FilterIndex = 1
Text1.Text = ""
.ShowOpen '或使用CommonDialog1.Action=1
Text1.Text = .FileName
End With
If Err.Number > 1 Then '如果打开文件正确
MsgBox "你打开的文件不正确!"
Exit Sub
End If
n = 0
arr(0)="" '这里需不需要这里先赋值?否则没有文件呢?那List1.List = arr赋值就会出错吧?'
StrText = Dir(CommonDialog1.InitDir &"\*.jpg")
While Len(StrText) > 0
n = n + 1
ReDim Preserve arr(1 To n)
arr(n) = Split(LCase(StrText), ".jpg")(0)
StrText = Dir 'DIR ()
Wend
List1.List = arr 报错说此句参数不对???
End Sub