Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


To hang up, we send the Hayes-compatible “ATH” command to the modem and set PortOpen to False to close the serial port:

Private Sub Command2_Click()
    MSComm1.Output = "ATH" & vbCr
    MSComm1.PortOpen = False
End Sub

Adding A MonthView Control To Your Program

The Testing Department is on the line again. Your financial planning program, BigBucks4U , is great, but what about displaying a calendar so the user can plan dates far into the future. You start thinking about the algorithm for determining the day of the week for any date throughout history—but there’s a better way.

You can use a MonthView control. That control displays the current month and lets the user scroll through other months as well. Just think of it as a handy calendar, because that’s what it’s designed to be.

To add a MonthView control to your program, just follow these steps:

1.  Select the Project|Components menu item.
2.  Click the Controls tab in the Components dialog box that opens.
3.  Select the Microsoft Windows Common Controls-2 entry, and click on OK to close the Components dialog box. This adds both the MonthView and DateTimePicker controls to the toolbox.
4.  Just draw the control as you would any other control in your form.

Now that you’ve added this control, how do you use it? See the next topic.

Getting Dates From A MonthView Control

When the user clicks a date in a MonthView control, the control creates a DateClick event. We can take advantage of that event to display the date the user clicked in a text box, using the MonthView’s Day, Month, and Year properties:

Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
    Text1.Text = MonthView1.Month & "/" & MonthView1.Day & _
        "/" & MonthView1.Year
End Sub

In fact, we’ve done too much here. You can do the same thing with the MonthView’s Value property, which holds the current date in mm/dd/yy format:

Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
    Text1.Text = MonthView1.Value
End Sub

The result of this code appears in Figure 13.8 (the red circle indicates today’s date).


Figure 13.8  Reading a date from a clicked MonthView control.

Notice also that we are passed a Visual Basic Date object in this procedure, corresponding to the date the user clicked. You can use the Format$() function as outlined earlier in this chapter to format the date held in that object in any way you wish.

The code for this example is located in the calendar folder on this book’s accompanying CD-ROM.


TIP:  If you enable a MonthView’s MultiSelect property by setting it to True, the user can select a number of dates in the MonthView (by using the Ctrl and Shift keys with the mouse). You can use the SelStart and SelEnd properties to determine the selected range.

Adding A DateTimePicker Control To Your Program

An easy way of letting the user select a date is to use a DateTimePicker control. The DateTimePicker control allows the user to specify a date or time. DateTimePickers can display a MonthView as a drop-down control, or the current time with an updown control to let the user select the time they want.

In particular, the control’s UpDown property determines which mode the control is in:

  UpDown = False means the control is in drop-down calendar mode (the default).
  UpDown = True means the DateTimePicker is in time format mode.

To add a DateTimePicker control to your program, just follow these steps:

1.  Select the Project|Components menu item.
2.  Click the Controls tab in the Components dialog box that opens.
3.  Select the Microsoft Windows Common Controls-2 entry, and click on OK to close the Components dialog box. This adds both the MonthView and DateTimePicker controls to the toolbox.
4.  Just draw the control as you would any other control in your form.
5.  Set the UpDown property as discussed in the preceding list to select calendar mode or time format mode.

Now that you’ve added the control, how do you use it? See the next topic.

Using A DateTimePicker Control

We’ll see how to let the user select a time using a DateTimePicker control here. Just add a DateTimePicker to your program and set its UpDown property to True (which means we’ll let the user set the time, not the date).

DateTimePicker controls have a Change event, and we’ll make use of that event to catch new time settings as the user makes them. In this case, we’ll just display the new time in a text box this way, using the DateTimePicker’s Value property:

Private Sub DTPicker1_Change()
    Text1.Text = DTPicker1.Value
End Sub

That’s all we need. Now the user can edit the hour, minute, and second of the time displayed in the DateTimePicker, and as soon as they make any change, we’ll display the new value in the text box, as shown in Figure 13.9. Our DateTimePicker example is a success. The code for this example is located in the timepicker folder on this book’s accompanying CD-ROM.


Figure 13.9  Using a DateTimePicker control.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.