• 0

[VB.NET] Opening File


Question

I'm just starting out with VB and I'm curious as to how I would open a file. I'm thinking of having a simple MP3 player as my first project (not some flashy thing with a playlist). Any help would be greatly appeciated.

In case you don't know what I'm talking about, I'll attach a screenshot of what I want.

post-47-1094313849.png

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

Yes, its called OpenFileDialog and should be pretty easy to use.

Dim openFileDialog1 As OpenFileDialog
openFileDialog1 = New OpenFileDialog()

openFileDialog1.InitialDirectory = "c:\temp\"
openFileDialog1.Filter           = "All files (*.*)|*.*"
openFileDialog1.FilterIndex      = 2
openFileDialog1.RestoreDirectory = True
If (openFileDialog1.ShowDialog() = DialogResult.OK) Then
     fName = openFileDialog1.FileName
     'blah
End If

From: http://www.codeguru.com/vb/gen/vb_misc/ico...icle.php/c5597/

Link to comment
Share on other sites

  • 0

An MP3 player, I have been learning VB.Net for two years now and to be honest you'd be better off building a small database app unless you are using VB.Net 2005 because playing sound in VB.Net 2003 mean playing with the API.

The sound playing commands in VB.Net 2005 have been greatly improved, so unless your using VB.Net 2005 I would not attempt and MP3 player as my first project !!!

Link to comment
Share on other sites

  • 0
Yes, its called OpenFileDialog and should be pretty easy to use.

Dim openFileDialog1 As OpenFileDialog
openFileDialog1 = New OpenFileDialog()

openFileDialog1.InitialDirectory = "c:\temp\"
openFileDialog1.Filter           = "All files (*.*)|*.*"
openFileDialog1.FilterIndex      = 2
openFileDialog1.RestoreDirectory = True
If (openFileDialog1.ShowDialog() = DialogResult.OK) Then
     fName = openFileDialog1.FileName
     'blah
End If

From: http://www.codeguru.com/vb/gen/vb_misc/ico...icle.php/c5597/

Thanks!! :D

An MP3 player, I have been learning VB.Net for two years now and to be honest you'd be better off building a small database app unless you are using VB.Net 2005 because playing sound in VB.Net 2003 mean playing with the API.

The sound playing commands in VB.Net 2005 have been greatly improved, so unless your using VB.Net 2005 I would not attempt and MP3 player as my first project !!!

Yeah, probably. But like I said it's only a simple thing. It virtually only consists of a browse button. :blush: Well, aesthetically only consists of a browse button.

Edited by Shannon
Link to comment
Share on other sites

  • 0
Yeah, probably. But like I said it's only a simple thing. It virtually only consists of a browse button. :blush: Well, aesthetically only consists of a browse button.

Cool, well let me know how you get on with your MP3 player ! :yes:

Link to comment
Share on other sites

  • 0
Cool, well let me know how you get on with your MP3 player ! :yes:

Well, I worked out how to exploit the WMP component to play MP3s. I even went as far as adding some playback buttons. The only thing I've got to do to make it complete now is work out how to update the text box to show the path of the file. Any ideas? :(

post-47-1094637338.png

Link to comment
Share on other sites

  • 0

Hi Shannon,

Try adding the following to your 'open file button' subroutine . . .

       
Dim selection As String = OpenFileDialog1.FileName
TextBox1.Text = selection

Once you have selected a file, the file name is placed into the string called selection and then you can make your textbox equal to the string.

Hope that helps !

Link to comment
Share on other sites

  • 0
Hi Shannon,

Try adding the following to your 'open file button' subroutine . . .

       
Dim selection As String = OpenFileDialog1.FileName
TextBox1.Text = selection

Once you have selected a file, the file name is placed into the string called selection and then you can make your textbox equal to the string.

Hope that helps !

Ahh... works like a charm! Thanks! :D

post-47-1094639765.png

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.