Results 1 to 5 of 5

Thread: showopen

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    13

    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?

  2. #2
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: showopen

    Try:
    vb Code:
    1. CD1.Filename = "*.txt"
    2. CD1.ShowOpen

  3. #3
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    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

  4. #4
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: showopen

    You also might want to add some flags...
    vb Code:
    1. CD1.Flags = cdlOFNHideReadOnly + cdlOFNPathMustExist + cdlOFNFileMustExist + cdlOFNLongNames + cdlOFNExplorer

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2007
    Posts
    13

    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
  •  



Click Here to Expand Forum to Full Width