Tutorials > Tutorial 14 - Navigating with TDBHolidayX |
This tutorial shows how navigation can be used with the TDBHolidayX object.
Start a new project.
From the Visual Basic Project menu, select References, then check the box labeled ComponentOne True DBHolidayX 8.0 Click OK to add the TDBHolidayX object to the project.
Place a ComboBox (cmbDayType), two labels, a ListBox (lstInfo), a CheckBox (chkDir), and two Command buttons (cmdOneDay, cmdOneMonth) on the form (Form1) as shown in the following figure.
We will use code to calculate the financial information that is displayed to the ListBox.
Example Title |
Copy Code
|
---|---|
' Declare a global TDBHolidayX object as global Dim HolidayMgr As New TDBHolidayX ' This sub mainly sets up the information for holiday and weekends. Sub Form_Load() ' Setup the national holiday style object and days. HolidayMgr.HolidayStyles.Add , "NH", "National Holidays" HolidayMgr.HolidayStyles("NH").Override = dbiOverrideNextDay With HolidayMgr.HolidayStyles("NH").Days .Add "1/1", , CDate("1999/1/1") .Add "1/15", , CDate("1999/1/15") .Add "2/11", , CDate("1999/2/11") .Add "3/21", , CDate("1999/3/21") .Add "4/29", , CDate("1999/4/29") .Add "5/3", , CDate("1999/5/3") .Add "5/5", , CDate("1999/5/5") .Add "7/20", , CDate("1999/7/20") .Add "9/15", , CDate("1999/9/15") .Add "9/23", , CDate("1999/9/23") .Add "10/10", , CDate("1999/10/10") .Add "11/3", , CDate("1999/11/3") .Add "11/23", , CDate("1999/11/23") .Add "12/23", , CDate("1999/12/23") End With With cmbDayType .AddItem "0 - Holiday" .AddItem "1 - Workday" .AddItem "2 - Weekends" End With ' Setup Saturday and Sunday as weekends. HolidayMgr.WeekRests(1) = -1 HolidayMgr.WeekRests(7) = -1 ' Set the holiday style to use for date processing. HolidayMgr.UseStyles = "NH" cmbDayType.ListIndex = 0 End Sub |
This code will determine when the DayType changes.
Example Title |
Copy Code
|
---|---|
' When the selection of DayType changes this sub is called Sub cmbDayType_Click() Dim FirstDay As Variant Dim LastDay As Variant ' Pickup first & last the day type in year. FirstDay = HolidayMgr.FirstInYear(CDate("1999/1/1"), cmbDayType.ListIndex) LastDay = HolidayMgr.LastInYear(CDate("1999/1/1"), cmbDayType.ListIndex) ' Clear the contents in the control. lstInfo.Clear ' Display the beginning and end date in year lstInfo.AddItem "First Date: " & FirstDay lstInfo.AddItem "Last Date: " & LastDay lstInfo.AddItem String(40, "-") ' Just to the first date. HolidayMgr.Value = FirstDay ' Display information concerning the date. DisplayTheDate HolidayMgr.ValueType End Sub |
This code will allow navigating by one day at a time.
Example Title |
Copy Code
|
---|---|
' Navigate a day at a time. Sub cmdOneDay_Click() ' If the check is on then that means move to next. If chkDir.Value = 1 Then ' Move to the next. HolidayMgr.Value = HolidayMgr.NextDay(, cmbDayType.ListIndex) Else ' Move to the previous. HolidayMgr.Value = HolidayMgr.PrevDay(, cmbDayType.ListIndex) End If ' Display information concerning the date. DisplayTheDate HolidayMgr.ValueType End Sub |
This code will allow navigating by one month at a time.
Example Title |
Copy Code
|
---|---|
' Navigate a month at a time. Sub cmdOneMonth_Click() Dim DateTmp As Variant Dim Month As Integer ' Retrieve which month we are in. Month = DatePart("m", HolidayMgr.Value) ' If the check is on then that means move to next. If chkDir.Value = 1 Then ' Process this only when before december. If Month < 12 Then ' Move to the next. DateTmp = HolidayMgr.FirstInMonth( _ DateSerial(1999, Month + 1, 1), cmbDayType.ListIndex) End If Else ' Process this only month is after January. If Month > 1 Then ' Move to the prev. DateTmp = HolidayMgr.FirstInMonth( _ DateSerial(1999, Month - 1, 1), cmbDayType.ListIndex) End If End If ' Display the date only when the date has changed. If HolidayMgr.Value <> DateTmp Then HolidayMgr.Value = DateTmp DisplayTheDate HolidayMgr.ValueType End If End Sub |
This code will determine the information about the date.
Example Title |
Copy Code
|
---|---|
' Display info about the date. Private Sub DisplayTheDate(TypeD As Integer) If TypeD And dbiValueWeekend Then If TypeD And dbiValueHolidayOrWordkay Then lstInfo.AddItem HolidayMgr.Value & " is a holiday and weekend." Else lstInfoAddItem HolidayMgr.Value & " is a weekend." End If ElseIf TypeD And dbiValueHolidayOrWorkday Then lstInfo.AddItem HolidayMgr.Value & " is a holiday." Else lstInfo,AddItem HolidayMgr.Value & " is a workday." End If End Sub |
If the checkbox is checked, the dates will increase; if unchecked, the dates will decrease.
This concludes Tutorial 14.