求助,真切求助,vb打开多个文件的问题

azhu1hao 2009-12-11 12:38:34
各位高手们,小弟近来做一项目,实为VB打开多个文件之问题烦恼,大牛们有vb打开多个文件的源码么,请发一份给我email好么,416226798@qq.com,谢啦!
...全文
136 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
东方之珠 2009-12-11
  • 打赏
  • 举报
回复
还是因为没有相应的程序打开文件!
东方之珠 2009-12-11
  • 打赏
  • 举报
回复
怎么打开的?如果是OPEN打开多个文件,其文件号必须用FreeFile函数动态取得;如果是用SHELL打开,是否因为内存不够?你没有说清楚!
jhone99 2009-12-11
  • 打赏
  • 举报
回复
打开多个文件和1个文件没有什么区别,lz的问题出在哪里?
  • 打赏
  • 举报
回复
List1.ListItems.Add
azhu1hao 2009-12-11
  • 打赏
  • 举报
回复
谢谢大家的帮助,小弟先贴出自己的代码,请指正,我用的是getopenfilename函数

Option Explicit
'这是从多文件名字符串分离出文件名的函数
Type DlgFileInfo
iCount As Long
sPath As String
sFile() As String
End Type
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As Long
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Public Function GetDlgFileInfo(strFile As OPENFILENAME) As DlgFileInfo
Dim sPath, tmpStr As String
Dim sFile() As String
Dim iCount As Integer
Dim I As Integer
Dim strFilename As String
strFilename = strFile.lpstrFile
On Error GoTo ErrHandle

tmpStr = OpenFile.lpstrFileTitle

If Left$(tmpStr, 1) = Chr$(0) Then
'Multiple Select
For I = 1 To Len(tmpStr)
If Mid$(tmpStr, I, 1) = Chr$(0) Then
iCount = iCount + 1
ReDim Preserve sFile(iCount) 'redim array
Else
sFile(iCount) = sFile(iCount) & Mid$(tmpStr, I, 1)
End If
Next I
Else
'single select
iCount = 1
ReDim Preserve sFile(iCount)
If Left$(tmpStr, 1) = "\" Then tmpStr = Right$(tmpStr, Len(tmpStr) - 1)
sFile(iCount) = tmpStr
End If

GetDlgFileInfo.iCount = iCount
ReDim GetDlgFileInfo.sFile(iCount)

If Right$(sPath, 1) <> "\" Then sPath = sPath & "\"
GetDlgFileInfo.sPath = sPath

For I = 1 To iCount
GetDlgFileInfo.sFile(I) = sFile(I)
Next I
Exit Function
ErrHandle:
MsgBox "function run error1!", vbOKOnly + vbCritical, "custom error information!"

End Function
'这是过程中的调用
Private Sub Command5_Click()
Dim OpenFile As OPENFILENAME
Dim IReturn As Long
Dim sFilter As String
sFilter = "*.*" & Chr(0)
With OpenFile
.lStructSize = Len(OpenFile)
.hwndOwner = Form1.hWnd
.hInstance = App.hInstance
.lpstrFilter = sFilter
.nFilterIndex = 1
.lpstrFile = String(123456789, 0)
.nMaxFile = Len(.lpstrFile) - 1
.nMaxFileTitle = .nMaxFile
.lpstrInitialDir = "c:\"
.lpstrTitle = "Use the comdlg API not the ocx"
.flags = OFN_ALLOWMULTISELECT
End With
Dim DlgInfo As DlgFileInfo
Dim I As Integer
List1.ListItems.Clear
DlgInfo = GetDlgFileInfo(OpenFile)

For I = 1 To DlgInfo.iCount
List1.ListItems.Add.Text = DlgInfo.sPath & DlgInfo.sFile(I)
Next I
End Sub
'我把文件名读取出来放置在listview中
'点击后提示byref参数类型不符

1,488

社区成员

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

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