Tutorials > Tutorial 6 - Using TDBCalendar with TDBDateX |
In this tutorial, you will learn how to use the calendar control together with the TDBDateX object. The following sample will retrieve the detail information for the selected date, and display the details in a listbox.
Start a new project.
From the Visual Basic Project menu, select Components, then check the box labeled ComponentOne True DBCalendar 8.0. Click OK to add the TDBCalendar and control icon to the toolbox. Select References, and then select labeled ComponentOne True DBDateX 8.0. Click OK to add the TDBDateX object.
Place a True DBCalendar control (tdbCalendar) and a ListBox (lstDetail) on the form (Form1) as shown in the following figure.
This code will call the code to obtain the information on the selected date.
Example Title |
Copy Code
|
---|---|
Private Sub Form_Load() Call tdbCalendar_Change End Sub |
5. This code will obtain the information on the selected date.
Example Title |
Copy Code
|
---|---|
Private Sub tdbCalendar_Change() ' Make an instance of the DateX object to use later. Dim DateInfo As New TDBDateX ' Single selection mode. tdbCalendar.MultiSelect = dbiMultiSelectNone ' Apply the selected date and calendar info to the Date info object. DateInfo.StartOfWeek = tdbCalendar.StartOfWeek DateInfo.Value = tdbCalendar.Value ' Clear the contents in the listbox. lstDetail.Clear ' Start displaying information of the date in the list box. lstDetail.AddItem "Information on " & DateInfo.Value ' Display the regular date information. lstDetail.AddItem String(40, "-") lstDetail.AddItem "Year: " & DateInfo.Year lstDetail.AddItem "Month: " & DateInfo.Month lstDetail.AddItem "Day: " & DateInfo.Day lstDetail.AddItem "Weekday: " & DateInfo.Weekday & " 1:Sun, 2:Mon…" ' Display which half or quarter of year. lstDetail.AddItem String(40, "-") lstDetail.AddItem RTrim(Mid("First Second", _ (DateInfo.Half - 1) * 6 + 1, 6)) & " Half of Year" lstDetail.AddItem RTrim(Mid("First Second Third Forth", (DateInfo.Quarter - 1) * 6 + 1, 6)) & " Quarter of Year" ' Display other information. lstDetail.AddItem String(40, "-") ' Check if date is in leap year. If DateInfo.IsLeapYear Then lstDetail.AddItem "This year is leap year" Else lstDetail.AddItem "This year is not leap year" End If ' Check the date status. If DateInfo.ValueIsNull Then lstDetail.AddItem "Date is Null" Else lstDetail.AddItem "Date is valid" End If ' Check if date is 'Today'. If DateInfo.Compare(DateInfo.Value, Date$) = dbiEqual Then lstDetail.AddItem "Date is same as system date" Else lstDetail.AddItem "Date isn't the same as system date" End If End Sub |
Click on a new date. Notice how the detail information for the date changes in the list box.
This concludes Tutorial 6.