How to select multiple files with: "OCX CommDlg cd"
Oct 17, 2023 2:44:35 GMT 1
Roger Cabo likes this
Post by (X) on Oct 17, 2023 2:44:35 GMT 1
There is a note in the help file under the section:
Dlg Open, Dlg Save Command
that implies the dialog open can not select multiple files...
Dlg Open, Dlg Save Command
that implies the dialog open can not select multiple files...
These bits are not allowed in GFA-BASIC:
OFN_SHOWHELP $00010
OFN_ENABLEHOOK $00020
OFN_ENABLETEMPLATE $00040
OFN_ENABLETEMPLATEHANDLE $00080
OFN_ALLOWMULTISELECT $00200
OFN_SHAREAWARE $04000
OFN_SHOWHELP $00010
OFN_ENABLEHOOK $00020
OFN_ENABLETEMPLATE $00040
OFN_ENABLETEMPLATEHANDLE $00080
OFN_ALLOWMULTISELECT $00200
OFN_SHAREAWARE $04000
I am not sure if it was meant to apply to CommDlg's cd.ShowOpen, but, I finally got it working with a little help from ChatGPT.
Mostly it was a matter of pressing on until I figured out how to access any extra strings past the first Chr(0) until no more strings are found. At first glance, for a multiple selection, the cd.FileName seems to only store the directory path. The selected file names are there, stored in the cd.FileName string, but, you have to go get them "manually" by looking past the chr(0)s for more strings until done.
Proc P_Select_Files
Ocx CommDlg cd
cd.Filter = "*.*"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' cdoAllowMultiSelect allows multiple selections.
' The user can select more than one file at run time by pressing the SHIFT key
' and using the UP ARROW and DOWN ARROW keys to select the desired files. When
' this is done, the FileName property returns a string containing the names of
' all selected files. The names in the string are delimited by spaces.
'
cd.Flags = _
cdoAllowMultiSelect | _
cdoExplorer | _
cdoHideReadOnly | _
cdoFileMustExist | _
cdoNoLongNames
cd.ShowOpen
Dim selectedFiles() As String
Dim startPos As Long
Dim endPos As Long
Dim i As Long
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Find the starting position of the first filename
'
startPos = 1
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Loop to find all selected filenames
'
While Mid(cd.FileName, startPos, 1) <> "" And _
Mid(cd.FileName, startPos, 1) <> Chr$(0)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Find the end position of the current filename
'
endPos = InStr(startPos, cd.FileName, Chr$(0))
If endPos = 0 Then
endPos = Len(cd.FileName) + 1 // Without the added 1, the last chr was dropped. (X)
End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Extract the filename
'
Dim filename As String
filename = Mid(cd.FileName, startPos, endPos - startPos)
Trace filename
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Add the filename to the selectedFiles array
'
ReDim selectedFiles(i)
selectedFiles(i) = filename
' Move to the next filename
i++
startPos = endPos + 1
Wend
Dim Sel_File_Count% = 0
If (i > 1)
Sel_File_Count = i - 1
Else
Sel_File_Count = i
EndIf
Debug "Selected file count=";Sel_File_Count
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Now, the selectedFiles array contains the individual filenames.
' selectedFiles(0) is the folder directory, and the rest are the selected
' filenames.
EndProc