Welcome back. In part 2 of my series in learning VB.Net I am going to teach you about items, let's go.




First we need to load our project, the file you want to open is TestApplication.sln.
Double click on MainForm.vb to open up the design view of it.


In this lesson we're going to use 3 different items. Items can be found on the left-hand side of the screen in the toolbox.
From the toolbox you can simply drag the item you want onto the form. We are going to add 1 label, 1 button and 1 textbox, simply drag them where you want them and then use your mouse to resize them, see the picture how it could look like now.




The label is just a part of text, we're going to use it just to tell the user what to do.
Select the label and in the properties change to this:

Code:
Name: lblInfo
Text: Enter your name and then press OK

The textbox is an item where the user can enter text during runtime (when the program is running). We are going to use it to let the user write something and then we're going to use it's value, Change this:

Code:
Name: txtInput

The button is used to call a bit of code, all items can do that in one way or another (the textbox can do it when the text changes for example) but the button is a good way to do it.
Change this:

Code:
Name: btnOK
Text: OK



Now we want to add some code to our application. You can right click on the form and then select view code but that's not the way we are going to use now.
We want something to happen when we someone click the button. Since this is the default thing for a button item we just double-click on the button and we will come to the code view with a sub added.
Subs is a part where you can add some code. The code will look like this:



Code:
Public Class MainForm

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

    End Sub
End Class


In the middle you can see a sub called btnOK_Click, at the end of the row you can see: Handles btnOK.Click. This means this code will go when the btnOK is clicked. At the beginning of the row you can see Private, this means the sub can only been acced from this form.


Now we are going to add our code in this sub. We want to know what text our text box has. To get a propertiy from an item we addd a dot and then that propertiy after. Like this:

Code:
txtInput.Text

We will use this value in a messagebox:

Code:
        MessageBox.Show(txtInput.Text)

Now if the user press the button a messagebox (a simple box with a message in) will show with the text in the textbox.
We can modify it a little:

Code:
        MessageBox.Show("Your name: " & txtInput.Text)

The quotes mean the text between them is a string (a text value) and the & is to add two strings togheter (txtInput.Text is also a string).


Now our code should look like this:


Code:
Public Class MainForm

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        MessageBox.Show("Your name: " & txtInput.Text)
    End Sub

End Class

Now test your you program by pressing F5. Write something in the textbox and then press ok to see the messagebox.

Save your project and we'll meet again in the next part, then I will teach you about the If...Elseif...Else statement.
Take Care