Member Avatar for Yivlx

If user enters a file path "C:\ProgramFiles\Blahblah\Blah.exe" in the textbox and presses enter it also changes the filepath in the code. How can I do that?

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Process.Start("C:\Users\Tj\Downloads\Catchem Releases\Catchem\Catchem.exe")
    End Sub

Can the same thing also be done for Button label/name?

Recommended Answers

All 5 Replies

Use the Text property of the TextBox. Something like this:

Process.Start(TextBox1.Text)

One thing to remember, anytime you're using user input, it's good practice to validate the information before using it.

In the KeyPres event of your textbox you can do something like this:

If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
    Process.Start(TextBox1.Text)
End If
Member Avatar for Yivlx

Sorry I'm new to Vb.net and Thank you for replying quick but am I doing this right?

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Process.Start(RichTextBox1.Text)
    End Sub
    Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox1.TextChanged
        If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
            Process.Start(RichTextBox1.Text)
        End If
    End Sub
Member Avatar for Yivlx

Fixed it but it breaks my application

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Process.Start(RichTextBox1.Text)
    End Sub

    Private Sub RichTextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles RichTextBox1.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
            Process.Start(RichTextBox1.Text)
        End If
    End Sub

The code you're using doesn't strip the return key. Try this:

Process.Start(RichTextBox1.Text.TrimEnd(vbCrLf.ToCharArray()))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.