Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Apr 2004
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    File Object (VB6)

    Hi

    I want to determine which file was selected from a DirListBox and FileListBox and return this value to a textbox.

    My code looks like this:

    Option Explicit
    Dim mFso As New FileSystemObject

    Private Sub dirDirectory_Change()
    filFile.Path = dirDirectory.Path
    End Sub

    Private Sub filFile_Click()
    Dim theFile As File

    TextBox.Text = ""

    Set theFile = mFso.GetFile(filFile.Path & " " & filFile.List(filFile.ListIndex))

    TextBox.Text = theFile
    End Sub

    Now although the code compiles okay, at Run Time I get a file not found error. I have Microsoft Scripting Runtime checked and have been over this code a dozen times and can't see what's wrong with it. So what am I missing please?

    Many thanks

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: File Object (VB6)

    Why don't you use the standard File Open dialog, either from the Common Dialog control or through API functions? The DirListBox and FileListBox are remnants from Windows 3.x.

  3. #3
    New Lounger
    Join Date
    Nov 2004
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Object (VB6)

    Hi

    Don't know anything about these. Will investigate and come back to you if any problems.

    Thanks

  4. #4
    Star Lounger
    Join Date
    Apr 2004
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Object (VB6)

    Hi

    Seem to have got the hang of these okay. One minor hiccup. When using the filter how do I get more than one file extension type to appear on the same line the way Windows does?

    My code:

    CommonDialog1.Filter = "Text Files (*.doc)|*.doc|(*.txt)|*.txt"

    Appears as two lines in the "type of files" dropdown. I would like to show all types of text files e.g. .doc .txt. htm. htm. rtf on one line.

    Have played around with the syntax but can't get the thing to work.

    Many thanks

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: File Object (VB6)

    You can include multiple extensions separated by semicolons:

    <code>CommonDialog1.Filter = "All Text Files (*.doc;*.txt;*.htm;*.rtf)|*.doc;*.txt;*.htm;*.rtf" </code>

  6. #6
    Star Lounger
    Join Date
    Apr 2004
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Object (VB6)

    Brilliant!

    Thanks very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •