|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
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 ProgramThe 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 historybut theres 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 thats what its designed to be. To add a MonthView control to your program, just follow these steps:
Now that youve added this control, how do you use it? See the next topic. Getting Dates From A MonthView ControlWhen 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 MonthViews 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, weve done too much here. You can do the same thing with the MonthViews 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 todays date).
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 books accompanying CD-ROM.
Adding A DateTimePicker Control To Your ProgramAn 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 controls UpDown property determines which mode the control is in:
To add a DateTimePicker control to your program, just follow these steps:
Now that youve added the control, how do you use it? See the next topic. Using A DateTimePicker ControlWell 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 well let the user set the time, not the date). DateTimePicker controls have a Change event, and well make use of that event to catch new time settings as the user makes them. In this case, well just display the new time in a text box this way, using the DateTimePickers Value property:
Private Sub DTPicker1_Change()
Text1.Text = DTPicker1.Value
End Sub
Thats 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, well 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 books accompanying CD-ROM.
|
|
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. |