Programmers write code. So we still need to write some for this lesson.
In Lesson 1, we wrote a very simple program that would display a date 30, 90, or 180 days from the current date. I suggested that you might think about how to change the program to go to your birthday at the very end. In this lesson, we'll start with the program that you coded in the first lesson and add a label that pops up if the date you go to happens to be your birthday.
Computers are clever, but they can't figure out what your birthday is unless you tell them. The first thing to add to the code is a way to tell the computer what your birthday is. In this particular case, I'm using a new statement: Const. This is a way of telling VB.NET about a value that will never change; in other words, a "constant". We'll see a different constant supplied by Visual Basic just a little later. I add this Const to the SkipDays class outside all of the subroutines at the top of the code. This makes the entire SkipDays class the "scope" of the Const. In other words, all of the procedures in the class will be able to use the same Const. The Const is coded like this:
Private Const myBDay As Date _
= #12/7/1941#
Notice that this is of type Date and that when a date is assigned to the Const, it's enclosed in the "#" symbols. Just as strings are enclosed in double quote marks in Visual Basic, dates are enclosed in pound symbols. That way, Visual Basic knows how to process them correctly.
Just one note on program design ... Coding something like this as a Const in the source code of the program is actually very bad design. If anyone else uses the program, the source code will have to be changed to a new date and the program will have to be recompiled. That's terrible design!! A much better way to do this would be to make this a parameter that is passed into the program from a configuration file. (And more advanced courses on this site show you how to do that.) I'm doing it this way to demonstrate how VB.NET works, not as an example of great programming.
Our modifications to the program will cause a big banner display to pop up the first time the program calculates a date on the same month and day as the date in myBDay. The banner can be dismissed again with a button.
To show the banner, add a Label component and then add a button to dismiss the banner. I named the banner label BDayGreet and the button BDayOK. I changed the background of the label to the color Fuchsia and I also changed the font Name and Size. And - very important - I set the Visible property to False so they will only be displayed when I want them to be.
But I didn't change the Text to my chosen greeting: "Happy Birthday To You!!". Why? Because there is no way to make the greeting appear on multiple lines by changing it in the Properties Window. If I had put it in the Text property using the Properties Window, it would all be on one long line and I want it to be on three lines so the banner is in a square that will cover the face of the MonthCalendar control.
But there is a way. This falls under the heading of programming tips and tricks. You'll learn lots of these as you gain skill as a programmer.
One of the events that you can use is the form Load event. This is a good way to do what is called "initialization" ... setting things up for the program. In the form Load event subroutine, I added the statement:
BDayGreet.Text = _
"Happy" & vbCrLf & _
"Birthday" & vbCrLf & _
"To You!!"
vbCrLf is a Visual Basic constant - one of many that you can use in your code. This particular one is equal to "carriage return line feed" characters. The use of these characters to force a new line goes back to the earliest days of programming - well before PC's were even dreamed of - but it's still supported. I use the "concatenation" operator "&" to insert a CrLf at the end of each line I want to appear and put that in the Text property when the form is loaded.
To control the display of the banner, I add this code after the new date is calculated:
If _
MonthCalendar1.SelectionRange.Start.Day = _
myBDay.Day And _
MonthCalendar1.SelectionRange.Start.Month = _
myBDay.Month And _
DidItAlready = False Then
BDayGreet.Visible = True
BDayOK.Visible = True
End If
(Just a reminder ... I use a lot of continuation characters - underscores - in my example code to keep the lines short so they will fit on the web page here. You don't have to use them if you copy this code.)
In words, the code above states that if the myBDay Day and Month is equal to the one calculated, make the label and button visible. And change this other variable "DidItAlready" to false. What's that all about?
Once the banner is dismissed (we'll code that next), I don't want this code to pop it up again. So I use this variable to make sure it only happens once. The variable also has to be declared in the same place that the Const was declared so it will also have class level scope:
Private DidItAlready As Boolean = False
The last thing we have to code is the Click event subroutine for the button to dismiss the banner:
Private Sub BDayOK_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles BDayOK.Click
BDayGreet.Visible = False
BDayOK.Visible = False
DidItAlready = True
End Sub
The end result looks like this when you hit your birthday:
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
Here's a download for the updated program in case you want to see exactly how I did it.

