There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen blue screen blue screen of death boot computer connection crash css dell display driver drivers email error ethernet excel firefox firefox 3 hard drive internet internet explorer itunes laptop malware monitor network networking outlook outlook 2003 outlook express partition password printer problem problems ram router security slow sound startup trojan usb video virus vista windows windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
How do i use OpenFileDialog in vb 2005


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
biddog989's Avatar
Computer Specs
Junior Member with 7 posts.
 
Join Date: Jan 2008
Experience: Beginner
20-Jan-2008, 07:56 PM #1
How do i use OpenFileDialog in vb 2005
Hi,
I have been playing around with the Windows Media Player component in visual basics 2005 on my XP pro computer. I created a listbox that was set up to look in a specific place when the form was loaded for mp3 files and when the user click on a file in the listbox it would play that file in the media player.

What I am now looking for is a way the user can browse files on their computer and add the files they want to the listbox. From what I have read off the net, I need to use the "OpenFileDialog" code but I have no idea how to do so.

Please note I’m an extreme beginner so you may have to spell the whole thing out for me

I have attached my vb 2005 files compressed using rar so you can see what I’m talking about, if you any suggestions you are more then welcome to share them.
Thanks
Attached Files
File Type: rar Code.rar (348.9 KB, 102 views)
artur02's Avatar
Computer Specs
Member with 91 posts.
 
Join Date: Sep 2007
Location: Hungary
Experience: Advanced
21-Jan-2008, 01:11 AM #2
You can read a description here: http://msdn2.microsoft.com/en-us/lib...92(VS.71).aspx

Take the following steps:
  1. Create a variable for OpenFileDialog
  2. Set members
  3. Call ShowDialog() and check for DialogResult, it should be OK
  4. Read FileName property for file path
The details are in the article linked above.
__________________
Artúr Herczeg
artur02
http://techies.teamlupus.hu
biddog989's Avatar
Computer Specs
Junior Member with 7 posts.
 
Join Date: Jan 2008
Experience: Beginner
21-Jan-2008, 05:10 AM #3
Thanks, I had a look at that website and I got some of the code working, as I said before I’m very new to visual basic so the steps you listed made nearly no sense to me but I did come out with this code for my button....

Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.Filter = "Mp3 Files|*.mp3"
openFileDialog1.Title = "Select a Mp3 File"
If openFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
ListBox1.Items.Add(openFileDialog1.FileName)
End If
End Sub

I know I’ve probably go very bad code any suggestions welcome

The button does let me select files to add to my listbox but the problem I have now is that I can only add one file at a time, is there a way that I can make it let me select more then one file at a time, remembering that each files source and name must be shown in the listbox
artur02's Avatar
Computer Specs
Member with 91 posts.
 
Join Date: Sep 2007
Location: Hungary
Experience: Advanced
21-Jan-2008, 11:52 AM #4
You should set Multiselect property to true. You can access the selected file names reading FileNames property. Read the articles below.

Multiselect: http://msdn2.microsoft.com/en-us/lib...ltiselect.aspx
Filenames: http://msdn2.microsoft.com/en-us/lib...filenames.aspx
biddog989's Avatar
Computer Specs
Junior Member with 7 posts.
 
Join Date: Jan 2008
Experience: Beginner
21-Jan-2008, 06:01 PM #5
Thanks again.

Got that working great, my last problem is trying to get the player to automatically go to the next song in the list box when the current song has finished playing. I got the listbox to move to the next song but the song doesn’t start playing, media player shows "opening media" but never plays

Have a look at my new code to see what I mean.
Attached Files
File Type: rar Code v2.rar (274.4 KB, 90 views)
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 10:14 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.