Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

How to make a Browse button

Open up Visual Basic

Insert a textbox, and button

Double click your button:

Make a variable called ofd

Code
Dim ofd As New OpenFileDialog

What this is: Declaring a variable called ofd and makes new OpenFileDialog

Now call your variable and give it a title and filter it.
Code
ofd.Title = "Select Your file!" : ofd.Filter = "(*.exe)|*.exe"

Now make an id statement that if the file was ok change the textbox's text to the file name.

Code
If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
      TextBox1.Text = ofd.FileName
      End If

Final Code:

Code
Private Sub ElegantThemeButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ElegantThemeButton2.Click
      Dim ofd As New OpenFileDialog
      ofd.Title = "Select Your file!" : ofd.Filter = "(*.exe)|*.exe"
      If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
      TextBox1.Text = ofd.FileName
      End If
    End Sub
(Jan 2, 2015 06:15 PM)CodeBinary Wrote:  
Code
If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
      TextBox1.Text = ofd.FileName
      Else : Exit Sub

      End If

Why are you handling the else and doing nothing with it when it will exit the sub regardless? Also, please don't use the colon when you're making tutorials... They're meant to be clear. What awful writing. Why does this irritate me so much?
It's not just you that it irritates. If you use it, atleast use it correctly, not like this.

And why are you exiting sub op? Do this its so much cleaner.

Code
Using ofd As New OpenFileDilaog With {.Filter = "Executable|*.exe"}
If ofd.ShowDialog = DialogResult.OK Then
' To stuff here
End If
End Using
(Jan 2, 2015 06:29 PM)+Haze Wrote:  It's not just you that it irritates. If you use it, atleast use it correctly, not like this.

And why are you exiting sub op? Do this its so much cleaner.

Code
Using ofd As New OpenFileDilaog With {.Filter = "Executable|*.exe"}
If ofd.ShowDialog = DialogResult.OK Then
' To stuff here
End If
End Using

Fixed it.

(Jan 2, 2015 06:19 PM)Odus Wrote:  Why are you handling the else and doing nothing with it when it will exit the sub regardless? Also, please don't use the colon when you're making tutorials... They're meant to be clear. What awful writing. Why does this irritate me so much?

I don't appreciate you being so rude I am just trying to help.
(Jan 2, 2015 06:34 PM)CodeBinary Wrote:  Fixed it.

I don't appreciate you being so rude I am just trying to help.

But if you're trying to help beginners, atleast advance from it yourself first.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by LeonieHackPetaBytes2Jan 23, 2019 05:10 PM 1 227 Jan 23, 2019 05:10 PM
Last Post: 0xDEAD10CC
[C#] by gigajewApr 18, 2018 03:39 AM 3 293 Apr 18, 2018 03:39 AM
Last Post: severos
[C#] by CipheredJun 8, 2016 05:36 PM 5 330 Jun 8, 2016 05:36 PM
Last Post: Corios