Up to this point, we still have not written any code for the SkipDays program. You may have accidentally created event subroutines while you were looking around. If you did, just highlight and delete them in the code window. (Leave the Public Class SkipDays - End Class statements there, however.) But now it's time to write some of our own code.
Using the Class Name and Method Name dropdown textboxes as described above, select the skipAhead control and the Click Event again so VB.NET will create the event subroutine for the Click event again. Then enter this code in the subroutine:
If skip30.Checked = True Then MonthCalendar1.SetSelectionRange( _ Today.AddDays(30), _ Today.AddDays(30)) ElseIf skip90.Checked = True Then MonthCalendar1.SetSelectionRange( _ Today.AddDays(90), _ Today.AddDays(90)) ElseIf skip180.Checked = True Then MonthCalendar1.SetSelectionRange( _ Today.AddDays(180), _ Today.AddDays(180)) End If
This is the only code we need to write to make the whole program work because the really difficult coding is part of the control. The code we do have to write is an example of "conditional statements". One of the main things you have to do as a programmer is decide how to control the program with conditions. In this case, we select a date on the MonthCalendar control based on which RadioButton is clicked.
But it's not quite that easy. You might be asking questions like, "Why is 'Today.AddDays' there twice?" and "Why did you use the 'SetSelectionRange' method?" These are all good questions. Let me ask you one: "How do you say, "Today is the first day of the rest of your life." in the Swahili language?"
You say you don't speak Swahili? Neither do I. But I do speak Visual Basic because I've studied it for years. This is an example of what you have to learn to "speak" it.
But there is a lot of help right at your fingertips. One of the first sources of help is "Intellisense". VB.NET will suggest all of the members that you might be looking for as soon as you enter the "dot" in the "dotted notation" above.
To see how this works, enter
into the code just before the End Sub statement. As soon as you enter the "dot" a window should open that displays the members - methods and properties - available for a Button control. You'll see the Name and Text properties there, for example. You'll notice that a lot of other "pop-up" help is available as you move your mouse around the code window too.
Click Here to display the illustration
Click the Back button on your browser to return
The Help system for VB.NET is exceptionally complete as well. It's amazing, especially when you think about how much you paid for it. (Nothing!)
And ... of course ... I recommend that you check out the articles and tips available at About Visual Basic, too!
At this point, your first program is complete, but it's far from perfect. For your first homework assignment, change the code to go to your birthday for any year!