哪位是高手?帮我解决这个问题给你50分!

hrbzzh 2003-08-21 09:38:01
就是CommonDialog中选择多个文件后怎么处理返回的文件名?都说是“c:\file1.ext_file2.ext_file3.ext"(_代表空格),可是我试了不好使,请赐教!
...全文
95 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hrbzzh 2003-08-24
  • 打赏
  • 举报
回复
谢谢各位拉
stonegoldaustin 2003-08-22
  • 打赏
  • 举报
回复
With CommonDialog1
.InitDir = App.Path
.Flags = cdlOFNAllowMultiselect
.Filter = "所有文件|*.*"
.ShowOpen
a = Split(.FileName, Chr(32))
ml = a(0)
For i = 1 To UBound(a)
MsgBox "Choice File:" & ml & a(i)
Next
End With
rainstormmaster 2003-08-21
  • 打赏
  • 举报
回复
CommonDialog控件的Flags属性有一个标志cdlOFNAllowMultiselect。利用这个标志可以实现多选。如:
CommonDialog1.Flags = CommonDialog1.Flags + cdlOFNAllowMultiselect
无论是在 Windows NT 4.0 还是在 Windows 95 中,如果 cdlOFNAllowMultiselect 标志被单独使用,都不能支持长文件名。这是因为多重文件名要包括空格分隔符,而长文件名也可能包括空格符。在 Windows NT 3.5 中,无法避免这种情况。如果使用 cdlOFNAllowMultiselect,就不能看到长文件名。如果在 Windows 95 中添加 cdlOFNExplorer 标志,就可以既能文件多选,又能看到长文件名。但是,这些文件名是用空字符Chr(0)分隔符,而不是空格分隔符隔开。因此,cdlOFNAllowMultiselect 和 cdlOFNExplorer 一起使用时,在 Windows 95 和 Windows NT 3.5中需要不同的文件名所得结果的语法分析。
当使用 cdlOFNAllowMultiselect 标志时,可能希望增加 MaxFileSize 属性的尺寸以便对所选文件名有足够的内存。MaxFileSize 属性要分配内存以便存储所选的一个或多个文件的实际名称。该属性的范围是 1-32K。缺省值是 256。
下面是一个例子:
Private Sub Command1_Click()
Dim I As Integer
Dim Y As Integer
Dim Z As Integer
Dim FileNames$()

CommonDialog1.FileName = ""
CommonDialog1.Filter = "All Files|*.*"
CommonDialog1.Flags = cdlOFNAllowMultiselect + cdlOFNExplorer
CommonDialog1.Action = 1

CommonDialog1.FileName = CommonDialog1.FileName & Chr(0)

Z = 1
For I = 1 To Len(CommonDialog1.FileName)
I = InStr(Z, CommonDialog1.FileName, Chr(0))
If I = 0 Then Exit For
ReDim Preserve FileNames(Y)
FileNames(Y) = Mid(CommonDialog1.FileName, Z, I - Z)
Z = I + 1
Y = Y + 1
Next

If Y = 1 Then
Text1.Text = FileNames(0)
Else
Text2.Text = ""
For I = 0 To Y - 1
If I = 0 Then
Text1.Text = FileNames(I)
Else
Text2.Text = Text2.Text & UCase(FileNames(I)) & _
Chr$(13) & Chr$(10)
End If
Next
End If
End Sub
danielinbiti 2003-08-21
  • 打赏
  • 举报
回复
split 推荐
replace都成

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧