--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
TryTells the program that it's going to try and run the code below it.
'Try to run the process inputed into the text boxThat 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 TryThis 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.CloseThe 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.







MultiQuote



|