Visual Basic Programming

Page 15

This page will build your understanding for the Debug window, also called the Immediate window. I believe that we used this window in the past. So let's begin.

Recall:

frmLoop.Top = (Screen.Height - frmLoop.Height) / 2
frmLoop.Left = (Screen.Width - frmLoop.Width) / 2

Line 1: Begins For loop; starts variable lngLine at zero and ends at 500000. Step 500: Increments lngLine in intervals of 500.
Line 2: Prints (writes) This is line, then the value of lngLine in the immediate window.
Line 3: Goes to the next value of lngLine

The Step keyword is new, but it simply means to take steps by the value whatever you specify (in this case 500). It will go from 0 to 500 to 1000 to 1500 and so forth up to 500000.

Now let's try another exercise.

Now let's code the application.

This simply declares the variable bytClicks as the Byte datatype. This variable will not go above 5, so we can use this datatype.

Line 1: Assigns an initial value to the variable bytClicks so that it has a base to increment from.
Line 2: Sets the form's caption to the value of bytClicks when the form loads.

frmDebug.Top = (Screen.Height - frmDebug.Height) / 2
frmDebug.Left = (Screen.Width - frmDebug.Width) / 2

bytClicks = bytClicks + 1
frmDebug.Caption = bytClicks

Line 1: Increment the variable bytClicks by 1.
Line 2: Display the value of bytClicks in the form's caption.

If you run the application, the form's caption will display the value of the Clicks variable and increment it each time you click the button or press the enter key. If you hold the enter key, the variable will increment very quickly. If you go above 255, you will get an error message saying Overflow, because the data type Byte only goes up to the value 255. Try the Integer data type to go up to 32,767 or the Long data type to go up to two billion.

Now we will use another debugging tool called a watch. A watch simply keeps track of an expression, or watches an expression, thus the name watch.

The line of code frmDebug.Caption = intClicks is highlighted in the code window, and the watches window says that the Value of the variable intClicks is 1.

If you would like, keep going through the same process to increment the intClicks variable.

I hope you learned a bit about debugging applications and watching expressions.

Now it is time to move on to Page 16.

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