Visual Basic Programming

Page 3

If some of your windows were not there, go to the menu View > Properties Window. Select others you need or want as necessary

Now we'll add some objects.

As you can probably imagine right now, I will teach you to hide and show these labels. Therefore it does not make sense to show a label when the user can already see it. Therefore:

This property determines whether it can respond to user events. Enabled False means that it cannot respond. You will notice at runtime you cannot click the button at all.

Before we right some code, here are some notes on the code window:

Another note: Good programmers always use comments. This will make my life much easier as well, because now you can just type the comments I provide when you write your code to ensure your understanding.

A comment is made with the ' mark, or apostrophe mark. They can be placed above and below code, as well as to the right of the line. I am not aware of any other places, but you will not need to use them elsewhere. Comments exist in every language that I know of.

Example: 'show the left label to the user.

To make a multi line comment, you use the underscore key( _ ). For example:

    'This is the first line of my comment _
    This is the second line of my comment _
    This is the last line of my comment

The underscore key also tells the code to treat the next line as part of the code written on the line above. This is can be very useful to programmers if they have a very long line of code to write. Traditionally, these are not multi-line comments, but the use of the underscore as seen above lets the comment expand to the next line.

Now lets write some code.

Object Box<-- OBJECT BOX

To understand this code, refer to the comments on each line. Remember: Object.Property. That is how the properties are set to something in coding.

The one other thing to understand about this code is that you need to look at the structure of the code window. Notice at the very top of the code window is the line Public Class frmHideShow. This line simply declares a class called frmHideShow, and gives the class a public scope. The keyword Public determines the scope. This allows other classes to communicate with this form. If the keyword were Private instead, the form becomes unusable to objects which are not a part of it. The keyword Class simply means that this form object consists of objects. A class is simply a group of objects. This form contains objects, such as the ones we added such as the label, text box etc. Because this form is made up of objects, it is called a class.

Notice how the code window separates each object on the form. Each command button has its own sub-procedure. A sub-procedure is simply a set of commands. The code we entered previously controls two different sub-procedures--

cmdHide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdHide.Click 

AND

cmdShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdShow.Click.

Let's just focus on the command button cmdHide. All this code is doing is setting up a sub-procedure (a set of commands) cmdHide. This code is called when the button cmdHide is clicked (set up at end of line Handles cmdHide.click). The underscore click (cmdHide_Click) is just the name of the object. Since we can code several different events for this command button, the "_Click" is added to create a different name for each sub-procedure in order to avoid conflict.

Moving on now...

If it does not work, make sure that each object's Visible property is set to True in the properties list.

Well, time to move on to Page 4.

Back to Top

Page 1 | Page 2 | Page 3 | Page 4 | Page 5 | Page 6 | Page 7 | Page 8 | Page 9 | Page 10 | Page 11

Page 12 | Page 13 | Page 14 | Page 15 | Page 16 | Page 17 | Page 18 | Page 19 | Page 20

Page 21 | Page 22 | Page 23 | Page 24 | Page 25 | Page 26 | Page 27 | Page 28 | Page 29 | Page 30