Beginner help with FolderBrowserDialog

C

chrisknapp

I'm learning VB and am making an application where I need a user to be
able to choose which folder his files are located in. The folder path
chosen will be stored as a string for later use in the application. I
tried adding FolderBrowserDialog to my form but can't figure out how to
get it to work. I'm just above the 'Hello World' level here. Thanks.
 
H

Herfried K. Wagner [MVP]

I'm learning VB and am making an application where I need a user to be
able to choose which folder his files are located in. The folder path
chosen will be stored as a string for later use in the application. I
tried adding FolderBrowserDialog to my form but can't figure out how to
get it to work. I'm just above the 'Hello World' level here.

Place a FolderBrowserDialog component on your form and add the code below to
a button's 'Click' event handler:

\\\
If _
Me.FolderBrowserDialog.ShowDialog() = _
System.Windows.Forms.DialogResult.OK _
Then
MsgBox(Me.FolderBrowserDialog.SelectedPath)
End If
///
 
C

chrisknapp

Place a FolderBrowserDialog component on your form and add the code below to
a button's 'Click' event handler:

\\\
If _
Me.FolderBrowserDialog.ShowDialog() = _
System.Windows.Forms.DialogResult.OK _
Then
MsgBox(Me.FolderBrowserDialog.SelectedPath)
End If
///


Very fast and excellent reply! Thank you very much. You made it much
easier than all the solutions I was finding on websites. It is working
beautifully now!

I added your code and replaced the MsgBox with -

strTestPath = (Me.FolderBrowserDialog1.SelectedPath)
txtTestPath.Text = (Me.FolderBrowserDialog1.SelectedPath)


Thanks again!

Chris
 
B

Bruce W. Darby

Chris,

Don't mean to make Herfried blush, but he's got a lot of good answers. My
abilities at coding are probably about the same as yours and he and the
others have helped me to learn a lot of stuff in a very short period of
time. One of the things that they have been able to show me is how to
condense my code to make it more efficient and, if you don't mind me adding
my two cents..
strTestPath = (Me.FolderBrowserDialog1.SelectedPath)
txtTestPath.Text = (Me.FolderBrowserDialog1.SelectedPath)

If you are using a control to store a value on your form, that value can be
called from anywhere in the code for that form at any time, so your two
lines of code can actually be condensed down to one line...

txtTestPath.Text = Me.FolderBrowserDialog1.SelectedPath

I found out that I really didn't need the parentheses either, thanks to...
blush... these fine folks.

HTH,

Bruce
 
C

Cor Ligthert [MVP]

Be aware that if you don't install the servicepack in version Net 1.1 you
can get very serious errors.

:)

Cor
 
C

chrisknapp

Bruce said:
Chris,

Don't mean to make Herfried blush, but he's got a lot of good answers. My
abilities at coding are probably about the same as yours and he and the
others have helped me to learn a lot of stuff in a very short period of
time. One of the things that they have been able to show me is how to
condense my code to make it more efficient and, if you don't mind me adding
my two cents..


If you are using a control to store a value on your form, that value can be
called from anywhere in the code for that form at any time, so your two
lines of code can actually be condensed down to one line...

txtTestPath.Text = Me.FolderBrowserDialog1.SelectedPath

I found out that I really didn't need the parentheses either, thanks to...
blush... these fine folks.

HTH,

Bruce


Thank you Bruce. I've changed it in my code!

Chris
 
H

Herfried K. Wagner [MVP]

I added your code and replaced the MsgBox with -

strTestPath = (Me.FolderBrowserDialog1.SelectedPath)
txtTestPath.Text = (Me.FolderBrowserDialog1.SelectedPath)

Just remove the brackets on the right side, they do not make sense here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top