Page 1 of 1

How to make a Run program in vb.net Rate Topic: -----

#1 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Posted 02 April 2010 - 10:37 AM

*
POPULAR

I figure the best way to learn how to program and how applications in Windows work is to try and make something similar to applications already on Windows. I will be making tutorials on how to make these programs and will update them a I improve them or you can post updates on them that you think are good. The first application we will look into is the "Run" application which if you do not know it is a program with a combo box that you type text in to and press a button and it opens the file. We will be making something similar to it. Instead of using a combo box we will be using a text box. There will be a button too. Lets start making our Run applications.

--Open up vb 2008 and create a new application and name it "Run tutorial" or what ever you like.

--If you have ever noticed in the Run program you can't maximize the window nor making larger or smaller at all. Were going want to do that with ours. Go to the properties of our form and change the name to "Run". Change the Form Border Style to "Fixed Dialog" I think it's called. Set the maximize button to false. Now you have a form that can't be resized.

--Add a text box to the form and change the name to "tbProcess".
> I will make a tutorial that will teach you modern Hungarian Notation.

--Add three buttons to the form and arrange them any way you like. Change the names to-"btnRun", "btnCancel", and "btnBrowse". Change the text to-"&Run", "Cancel", and "Browse"(the "&" before the o says that we want a shortcut key. If you press ALT-R then the buttons code will start processing.) Then add a OpenFileDialog to the form.

-- Double click btnRun and add this code:
 Try

            'Try to run the process inputed into the text box

            Process.Start(tbProcess.Text)

        Catch ex As Exception

        End Try

> Now I will break that code down for you
Try
Tells the program that it's going to try and run the code below it.

'Try to run the process inputed into the text box
That is what is called a comment. A comment is made to make it easier for someone reading your code or even you know what is going to happening below in a form that you can understand.

Process.start(tbProcess.Text)
This means that what ever you inputed into tbProcess will atempt to start. It will be like when you click an icon to open up an application.

End Try
This tells the program to end trying to open up the program if it don't.

Double click btnCancel and add the following code:
Me.Close

> What this all basically means is that you want to send the shut down signal to the program. Some people use this code because they think their so much of an expert with vb.net
Form1.Close
The reason that code won't work is because the form is referring to it's self. The easiest way to remember to "me" is that you don't go out into public and say "Terry is happy" or something like that.(My name is Terry) But yet again "Me" don't make sense then also so what I would do now is look at the code and say to myself "I.Close" and "Me.Close" and tell which one is more catchy which "Me.Close".

Double click btnBrowse and add the code below:
 'Declare variable

        Dim strFileName As String



        'Set the Open dialog properties

        With OpenFileDialog1

            .Filter = "Programs |*.exe|All Files |*.*"

            .Title = "Browse"

            .FileName = ""

        End With



        'Show the Open dialog and if the user clicks the Open button,

        'load the file

        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

            Try

                'Save the file path and name

                strFileName = OpenFileDialog1.FileName



                Dim fileContents As String

                fileContents = My.Computer.FileSystem.GetName(strFileName)



                'Display the file contents in the text box

                tbProcess.Text = fileContents

            Catch ex As Exception



            End Try

> Now to sum up this code. What your doing by adding this is telling the program that you want to open a "OpenFileDialog". You want the filter to look for .exe files. You want the title of the dialog to be Browse. And you want the combo box where the program you click on name would appear to be nothing when you open it up. If you press "OK" you want the program to save the file name for latter use. You want to make the file content a string and find the path for the file name. Then you want the file content(the file name) to be displayed in tbProcess.

I hope you enjoyed the tutorial. If you liked it press the thumbs up button below this post. If you didn't don't be afraid to press the thumbs down button. If you have any questions leave a comment or send me a message.

Is This A Good Question/Topic? 9
  • +

Replies To: How to make a Run program in vb.net

#2 Aki Maki Ultimate  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 11-July 12

Posted 11 July 2012 - 03:08 AM

For btnRun, just use


Private Sub btnRun_Click(sender As System.Object, e As System.EventArgs) Handles btnRun.Click
        Process.Start(TextBox1.Text)
    End Sub

Was This Post Helpful? 1
  • +
  • -

#3 EnvXOwner  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 357
  • View blog
  • Posts: 2,319
  • Joined: 10-August 09

Posted 11 July 2012 - 06:15 PM

When I wrote this tutorial I was 12 and not very good with VB.net, I actually stopped learning it as I moved into web development. Thanks for the comment though :). It's probably more efficient than what I did!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1