|
-
Apr 5th, 2008, 08:44 PM
#1
Thread Starter
New Member
showopen
A dumb question no doubt - my apologies
Here's the snipet of my code
CD1.Filter = "All Files (*.txt)"
CD1.ShowOpen
If CD1.FileName = "" Then Exit Sub
myfile = CD1.FileName
The problem is when I try to re-open the CDialogue box to add more files ... I get an "Invalid filename" error ... leading me to the CD1.showopen command.
What am I doing wrong?
-
Apr 5th, 2008, 09:09 PM
#2
Re: showopen
Try:
vb Code:
CD1.Filename = "*.txt" CD1.ShowOpen
-
Apr 5th, 2008, 09:09 PM
#3
Re: showopen
Is there more code than that? Try something like this as a template for selecting a file...
Code:
Private Sub Command1_Click()
Dim strMyFile As String
On Error GoTo ErrorHandler
With CD1
'Raise an error if they press cancel
'(So we know if they pressed cancel).
.CancelError = True
.DialogTitle = "Open File"
.Filter = "All files (*.*)|*.*"
.Flags = cdlOFNFileMustExist 'File must exist
.ShowOpen
strMyFile = .FileName
'Or just the file title...
'strMyFile = GetAfterLast(.FileName, "\")
End With
Exit Sub
ErrorHandler:
If Err.Number <> cdlCancel Then
'Error other than them pressing cancel.
MsgBox Err.Description, , "Error (#" & Err.Number & ")"
End If
Exit Sub
End Sub
'Here's a function you can use to get just the file title or extension.
'ex: title: GetAfterLast(Path, "\")
'ex: extension: GetAfterLast(Path, ".")
Private Function GetAfterLast(ByRef Expression As String, _
ByRef AfterWhat As String) As String
Dim l As Long
l = InStrRev(Expression, AfterWhat)
If l > 0 Then GetAfterLast = Mid$(Expression, l + Len(AfterWhat))
End Function
-
Apr 5th, 2008, 09:16 PM
#4
Re: showopen
You also might want to add some flags...
vb Code:
CD1.Flags = cdlOFNHideReadOnly + cdlOFNPathMustExist + cdlOFNFileMustExist + cdlOFNLongNames + cdlOFNExplorer
-
Apr 5th, 2008, 09:34 PM
#5
Thread Starter
New Member
Re: showopen
This is the code I have - after changing to the first example, it worked fine.
I'm chewing over the other code ... may need new teeth.
Thanks!
CD1.Flags = cdlOFNExplorer Or cdlOFNAllowMultiselect
Dim myfile As String
Dim k0 As Integer
Dim k1 As Integer
Dim nullvar As Boolean
inputdata.Text = ""
CD1.Filter = "All Files (*.txt)"
'CD1.ShowOpen
CD1.FileName = "*.txt"
CD1.ShowOpen
If CD1.FileName = "" Then Exit Sub
myfile = CD1.FileName
' check for multiple files
For k0 = Len(myfile) To 1 Step -1
If Mid(myfile, k0, 1) = vbNullChar Then
nullvar = True
infiles.AddItem Right(myfile, Len(myfile) - k0)
End If
Next k0
For k0 = Len(myfile) To 0 Step -1
If Mid(myfile, k0, 1) = "\" Then
k1 = k0
Exit For
End If
Next k0
If nullvar = False Then
mylocation.Text = Mid(CD1.FileName, 1, k1)
infiles.AddItem Right(myfile, Len(myfile) - k1)
Else:
mylocation = Mid(CD1.FileName, 1, k1) & Right(myfile, Len(myfile) - k1) & "\"
End If
infiles.Selected(infiles.ListCount - 1) = True
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
|