Results 1 to 10 of 10

Thread: How Do I create a nice file selector form?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    166

    How Do I create a nice file selector form?

    I am adding the ability for the user to select a file and attach it to an email that my program sends out. (see the other thread about recycling an email form for more on this)

    My question is what controls can I use to create a nice GUI that lets the user select a file to attach? Does anyone hve any code they are willing to share that does this sort of thing?

  2. #2
    Lively Member Garrcomm's Avatar
    Join Date
    Jul 2009
    Location
    the Netherlands
    Posts
    87

    Re: How Do I create a nice file selector form?

    You could use the Windows Common Dialog for this:



    It's available as activex control in Visual Basic named "Microsoft Common Dialog Control" / comdlg32.ocx.
    If you want to do it without activex controls, which I prefer, you can also use the GetOpenFileNameA API-call. A function wrapper for this call can be found at http://www.stefanthoolen.nl/basic/vb...ction=OpenFile
    If you use that function, this code would be enough to let the user select a file:
    Code:
        Dim filename As String
        filename = OpenFile(Me.hwnd, "MP3-files|*.mp3", "Select an MP3-file")

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    166

    Re: How Do I create a nice file selector form?

    Wow, I added the Windows Common Dialog control to a form and then ran my app in the VB IDE. When I got to the form where the common control was, nothing happened.

    So I stopped the program and right clicked on the common control and went down to properties, I got an hourglass for a long time, then an UNknown hard error. After that I had no choice but reboot my computer.

    I threw away the form containing the common control. it seemed too dangerous

    Im running windows xp sp3 with 2gb of ram if your wondering

  4. #4
    Lively Member Garrcomm's Avatar
    Join Date
    Jul 2009
    Location
    the Netherlands
    Posts
    87

    Re: How Do I create a nice file selector form?

    Thats why I use API's instead of activex controls. I want to use as less dependencies as possible. Have you tried the module from the above URL?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    166

    Re: How Do I create a nice file selector form?

    I downloaded it, but I have not tried it in my app yet

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How Do I create a nice file selector form?

    I've used the common dialog control in projects beyond count since VB3 and I've never, ever had an issue with it.

    Are you sure you used the Microsoft Common Dialog control found under Project/Components?

  7. #7
    Lively Member Garrcomm's Avatar
    Join Date
    Jul 2009
    Location
    the Netherlands
    Posts
    87

    Re: How Do I create a nice file selector form?

    A little bit offtopic perhaps, but to explain something;
    I have had many problems with ocx-files myself. I tried betas of Visual Basic and they had their own revisions of ocx-files as well. I encountered loads of version conflicts due to this which made my applications fail on other computers then my own.
    Currently I work on Windows Vista and if I add an ActiveX control it simply crashes if I'm not running VB with Administrator-rights.
    Therefor I decided to avoid using ocx-files as much as possible. Also, using API's give better performance, although I doubt this is worth mentioning.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    166

    Re: How Do I create a nice file selector form?

    That API function will work well for my needs, thank you. I just have one question. How do I call the function so that the filter is set to all files?

  9. #9
    Lively Member Garrcomm's Avatar
    Join Date
    Jul 2009
    Location
    the Netherlands
    Posts
    87

    Re: How Do I create a nice file selector form?

    You can enter multiple filters, for example
    Filter = "All files|*.*" ' One option is available, to show all files
    Filter = "Text files|*.txt;*.rtf|All files|*.*" ' Two options are available, one for textfiles and one for all files

    You can add as many filters as you like.

  10. #10
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: How Do I create a nice file selector form?

    Quote Originally Posted by vbguy2008 View Post
    Wow, I added the Windows Common Dialog control to a form and then ran my app in the VB IDE. When I got to the form where the common control was, nothing happened.

    So I stopped the program and right clicked on the common control and went down to properties, I got an hourglass for a long time, then an UNknown hard error. After that I had no choice but reboot my computer.

    I threw away the form containing the common control. it seemed too dangerous

    Im running windows xp sp3 with 2gb of ram if your wondering
    I have been using the Windows Common Dialog Control since 1998.
    I have used it on windows 2003 server and windows XP. No issues so far.
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

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