Step 1:
Click on Start Button on Windows 7.
Step 2:
Then hover on All programs. And then click on the Microsoft Visual Studio 2010.
Step 3:
Now on the Start page, click on New Project.
After you click on "New Project", you will find a new pop up window something like this-
Now click on Visual Basic from the left panel and select Windows Forms Application from the right side. Then you can change the Project name if you wish. Then click OK.
Step 6:
Now you can see a small form in left corner of the application and Toolbox in the left side.
Let's add a text box:
a text box is a text area that allows the user to enter text.
Step 8:
In the Tool Box on the left, click on "TextBox".
Step 9:
Draw a shape on the form to draw the TextBox.
After placing the TextBox on the form, you can move anywhere on the Form.
Step 11:
Now insert a label. Find the label control from the toolbox and place it on the form.
The Properties window will appear on the right. Change the property of Text to Name. Make sure the Label1 is selected:
Add a new Textbox and a new Label and a button as the picture below, and name the second change the new label's text properties to Last and the button's text to Get Name:
Here comes the fun part: WRITING THE CODE
Double click on the new button that says "Get Name" to go to the codes page.
Step 15:
In the code window you will find something like this-
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button1.Click
End Sub
End Class
Step 16:
Now we will tell the form to produce a message box and show the name and the last name when we click on "Get Name"
Step 17:
You will enter this code between the second line and the third line:
MsgBox("My Name is " & TextBox1.Text & " " & TextBox2.Text)
Step 18:
Now Go the Debug Menu and then click Start Debugging or press F5 or click this icon from the toolbar-
Now enter a name inside the first text box, and a last name inside the second text box, and then click on "Get Name" and you should get something like this:
- Did you see how easily we built our first vb application. You entered the controls easily, part of the code was generated by itself, and we had to add a very small piece of code.
You might wonder how and where did we get the code from. Well let's analyze how we came out with that code.
Since that the program generates part of the code for us, let's not worry now how the software does that. Let's look at the code we wrote:
MsgBox("My Name is " & TextBox1.Text & " " & TextBox2.Text)
MsgBox: We told the program to display a message box that tells us whatever we entered in the form.
Write after MsgBox notice that we added ( . Whatever we enter between the two parenthesis is going to show on the message box. There are two kinds to show the text: directly and indirectly. If a text is entered between 2 quotations mark like: "My Name is " is shown exactly as is. Now we wanted to show what inside the text area that the user enters on the form. We added & TextBox1.Text , that means we wanted to show the text in the first text box that is named Textbox1 by default.
If you've finished this application and could build and run it properly, let's proceed to other visual basic projects.