This is a great place to shift the focus to debugging. You might be asking, "Why are you testing the variables FirstDateSave and SecondDateSave for the value #12:00:00 AM#?"
I've got two answers.
First, this might not be the best way to test whether a value has been entered. This might just introduce a new, and very subtle bug. What if the date selected really is #12:00:00 AM#? (But for purposes of this tutorial, it's still good. The program runs correctly nearly all the time.)
For more bulletproof code, it's usually a better idea to use an internal variable that is totally under the control of the program. Part of the code might look something like this:
Dim DateSelected as Boolean = False
. . .
If DateSelected = False Then ...
Breakpoints and QuickWatch
Second, however, I used a "breakpoint" and the "QuickWatch" feature of Visual Studio to find out just exactly what FirstDateSave and SecondDateSave did have in them before a date was selected in the MonthCalendar component. Then I just used the same value in the test in my code.
These are just two of the debugging tools in Visual Studio's very useful collection that you can use to figure out what, exactly, is happening when your code runs. There are too many to cover them all here, but I'll explain these two and then briefly list the most important of the rest.
(Here's a more technical answer, for those who still want more. In VB.NET, dates start at 12 AM on the first day of the Gregorian calendar. They're represented internally by an 8-byte number. An uninitialized date is all zeros, which is the same as the beginning of the VB.NET date range.)
A "breakpoint" in Visual Studio is a line of code where execution will be temporarily halted while the program is being run in "debug mode". Running in "debug mode" is just running the program under the control of Visual Studio so you can use Visual Studio's debugging tools. The reason for "setting a breakpoint" is to see details about your program at that point, or sometimes just to see if the program ever executes that line of code.
Here's a breakpoint being used to see what the values of FirstDateSave and SecondDateSave are:
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
You can "set a breakpoint" by clicking in the left margin opposite the line of code where you want the program to halt. A red ball should appear. Then you can "run" the program in debug mode by clicking the "Start Debugging" icon in the Debug toolbar. (There are several ways you can do most things in Visual Studio. You can also click "Start Debugging" in the Debug menu or just press F5.)
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
The illustration shows the value in a tooltip. For more complete information about any object in your code, select the object, right-click to display the "context menu" for the object, and select "QuickWatch". For complex objects, there can be quite a bit of information available.
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
Debug Mode and Single Stepping
Running a program in "debug mode" is the main method you will use for debugging. You can do that with breakpoints as already explained, or you can do it one statement at a time for more control and a better view of just what the program is doing. This is called "single stepping" through the code and you can do that by pressing F8 to start the program or after it has halted at a breakpoint. You should single step through a program (the Days Between Dates program is a good one to use) just to make sure that you understand what happens.
The Debug Object
Rather than watching the program while you're running it, many programmers prefer to capture key information and then look at what happened after the program runs. (This can be a useful technique if the program is very large, or if you just can't be there when it runs.) To do this, VB.NET gives you the "Debug" object that make it easy to capture the information they need. Here's a VB.NET Intellisense list of the some of the methods and properties available with Debug:
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
Using all of the features of Debug is an advanced topic. If you just want to show the value of a variable while a program is running, the Console.Writeline statement that I used in the first illustration above is a good option too. Keep in mind that Debug displays output in the Immediate window and Console displays it in the Output window as shown below.
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
This is the last lesson in our "beginner" tutorial. Now that you know the basic concepts, you're not a beginner anymore! Try some of the other tutorials and articles on the site.

