Visual Basic Programming

Page 11

As I explained earlier in this tutorial, If Then statements usually test variables. On this page, I will show you how you may do so. We will make a command button multi-functional without using checkboxes or radio buttons. I will also introduce the timer control to you.

Now for the timer control. The timer simply executes statements in intervals according to the interval property.

The Left property simply determines an objects position to the left and right of the form as you noticed.

(Probably getting tired of seeing this step written out huh? OK!! Now YOU need to remember it from now on!)

If you run the program, you see the label cross the form from left to right after you click the command button.

Now lets declare a variable.

This creates a form-level variable that stores values up to 255. We will not go above 2.

Now I will show you how to do a very basic procedure using the timer control again. Specifically, displaying the time with the Time$ function.

Now we will code the application

The line above simply tells the computer to display the time in the form's caption. If you run the application, you will notice that the time updates and that it is in a 24-hour format, as opposed to 12-hour format (AMPM). To change this, simply use the format statement we used earlier as seen below:

The line above should be written in the Timer control as done before. This line sets the time format to 12-hour format as you might have guessed.

Now we can display the date using the Date$ function. In the form load event in the code window (double-click form), type the following code:

The line above puts today's date the the label lblDate. Notice how it displays as 00-00-0000 format. To change this, we can use the format command again to change it as we please. The following line displays the full date:

The quotes take the spaces and commas as literals, so make sure that you typed it (or pasted it) EXACTLY as shown above.

There are TONS of different ways I could have introduced the Timer control. Try to experiment with it a bit to teach yourself more.

I hope this tutorial made sense to you. Hope you enjoyed it as well. Now it is time to proceed to Page 12.

Top of Page

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