Results 1 to 4 of 4

Thread: How to read the value from textbox and use as file path?

  1. #1
    New Member
    Join Date
    Aug 12
    Posts
    2

    How to read the value from textbox and use as file path?

    Hi all,

    I am a beginner in Visual Basic. I use Visual Studio 2008.

    I don't know how to solve this problem.
    I would like to run a file name xyz.exe from "c:\test\number\" directory.
    I have a browse button (Button3) to set the working directory ( c:\test\number\), and the path is shown in my TextBox1.
    I would like to get the Run button (Button1) to run the xyz.exe file from the previously selected directory.


    The code for Button3

    Code:
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            Dim BrowseFolder As New FolderBrowserDialog
            BrowseFolder.ShowDialog()
            TextBox1.Text = BrowseFolder.SelectedPath
            MsgBox(BrowseFolder.SelectedPath)
        End Sub

    The code for Button1

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                   System.Diagnostics.Process.Start( "\xyz.exe")
        End Sub
    Can you please help me to solve this problem?

    Thank you

    Poli

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,538

    Re: How to read the value from textbox and use as file path?

    Slightly odd way of going about it but ...

    Process.Start(TextBox1.Text & "\xyz.exe")

  3. #3
    New Member
    Join Date
    Aug 12
    Posts
    2

    Re: How to read the value from textbox and use as file path?

    Great,
    Thank you.

    Only one more question:
    How can I make that if the selected folder doesn't contain the file a msgbox says there is no file in selected directory and after hitting OK, it goes back to my panel and not freeze?

    Thank you again for your help

  4. #4
    Loquacious User Shaggy Hiker's Avatar
    Join Date
    Aug 02
    Location
    Idaho
    Posts
    20,408

    Re: How to read the value from textbox and use as file path?

    Take a look at the various classes in System.IO. There should be a path object, and a file object (though one of those may not actually be an object). You can use the tools in there to figure out various things, such as whether or not the user entered a valid path, whether or not the file exists, and so forth. You want to check out that entry before calling Start.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •