|
-
Nov 7th, 2008, 10:10 AM
#1
[RESOLVED] CommonDialog: error when selecting multiple files
I'm selecting multiple files by means of a common dialog and get error 20476 which means the .FileName property buffer is too small to hold all the file names. However I had selected only 6 files with 28 characters each. Anyone knows the character limitation? Is there any other reason why this should fail?
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Nov 7th, 2008, 11:37 AM
#2
Re: CommonDialog: error when selecting multiple files
A peek at your code would have helped 
However this is something which I often use....
http://support.microsoft.com/kb/198974
See if this helps...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Nov 7th, 2008, 12:22 PM
#3
Re: CommonDialog: error when selecting multiple files
This works just fine for me
Code:
Private Sub Command1_Click()
Dim sArrFileList() As String
Dim i As Long
With CommonDialog1
.CancelError = False
.InitDir = "C:\"
.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|" & _
"Batch Files (*.bat)|*.bat|" & _
"Word Documents (*.doc)|*.doc"
.Flags = cdlOFNAllowMultiselect + cdlOFNExplorer
.ShowOpen
End With
sArrFileList = Split(CommonDialog1.FileName, Chr(0))
For i = 0 To UBound(sArrFileList())
List1.AddItem sArrFileList(i)
Next
'also addes the drive
'letter which we
'do not want
List1.RemoveItem 0
End Sub
-
Nov 7th, 2008, 12:28 PM
#4
Hyperactive Member
Re: CommonDialog: error when selecting multiple files
Instead of adding the first item which is the C:\ then removing it afterwards, you could just Loop starting at 1 instead of 0.
-
Nov 7th, 2008, 01:31 PM
#5
Re: CommonDialog: error when selecting multiple files
 Originally Posted by koolsid
I don't think the code is (completely) wrong as it works in some instances like fewer files at a time.
VB Code:
'...
FilterText = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
If Not GetFileNames(FilterText) Then Exit Sub
'...
'
Private Function GetFileNames(ftxt) As Boolean
Dim i As Integer
Dim chunk() As String
Dim dirstr As String
On Error GoTo GetFileNames_Error
GetFileNames = False
With CommonDialog1
.CancelError = True
'File name must be reset to allow browsing to a different initial
'directory because the common dialog remembers the last one used
.FileName = ""
'Allow multiple selection
.flags = cdlOFNAllowMultiselect Or cdlOFNExplorer
'(DataDir is a public variable initialized elsewhere)
.InitDir = DataDir
.Filter = ftxt
.Action = 1 'Open
End With
chunk = Split(.FileName, Chr(0))
If UBound(chunk) = 0 Then
'Only one file was selected
'selFiles() is a string array declared at form level
ReDim selFiles(0)
selFiles(0) = chunk(0)
Else
'Multiple files were selected
dirstr = chunk(0) & "\"
ReDim selFiles(UBound(chunk) - 1)
For i = 1 To UBound(chunk)
selFiles(i - 1) = dirstr & chunk(i)
Next
End If
GetCalFiles = True
Exit Function
GetFileNames_Error:
'Selection cancelled out
Files = ""
On Error GoTo 0
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure GetFileNames"
End Function
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Nov 7th, 2008, 03:19 PM
#6
Re: CommonDialog: error when selecting multiple files
commondialog has a maxfilesize property that allows you to increase the size of the returned string
the default is 256 characters, can be up to 32k
from msdn
Remarks
The MaxFileSize property allocates memory to store the actual names of the selected file or files. When using the cdlOFNAllowMultiselect flag, you may want to increase the size of the MaxFileSize property to allow enough memory for the selected file names.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 10th, 2008, 08:30 AM
#7
Re: CommonDialog: error when selecting multiple files
 Originally Posted by westconn1
commondialog has a maxfilesize property that allows you to increase the size of the returned string
the default is 256 characters, can be up to 32k...
That was it
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|