1 / 31

Tutorial 14 – Shipping Time Application Using Date s and Timer s

Tutorial 14 – Shipping Time Application Using Date s and Timer s. Outline 14.1 Test-Driving the Shipping Time Application 14.2 Date Variables 14.3 Building the Shipping Time Application: Design Elements 14.4 Creating the Shipping Time Application: Inserting Code 14.5 Wrap-Up.

wang-hodges
Download Presentation

Tutorial 14 – Shipping Time Application Using Date s and Timer s

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tutorial 14 – Shipping Time ApplicationUsing Dates and Timers Outline 14.1 Test-Driving the Shipping Time Application14.2 Date Variables14.3 Building the Shipping Time Application: Design Elements14.4 Creating the Shipping Time Application: Inserting Code14.5 Wrap-Up

  2. Objectives • In this tutorial, you will learn to: • Create and manipulate Date variables. • Execute code at regular intervals using a Timer control. • Retrieve Date input with a DateTimePicker control. • Group controls using a GroupBox control.

  3. 14.1 Test-Driving the Shipping Time Application

  4. DateTimePickerwith up-down arrows GroupBoxes 14.1 Test-Driving the Shipping Time Application Figure 14.1 Shipping Time application.

  5. 14.2 Date Variables • Keyword New • Calls a structure’s constructor • Example: New Date(2003, 1, 1, 0, 0, 0) • Constructors initialize class objects or structure values • Datevariable • Stores information about a point in time • Contains properties Year, Month, Day, Hour, Minute, and Second

  6. 14.2 Date Variables Figure 14.2 Date constructor arguments.

  7. Visual Basic .NET statement Result Assume has been initialized with a value. dtmDelivery Date dtmDelivery = dtmDelivery.AddHours( 3 ) Add hours. 3 dtmDelivery = dtmDelivery.AddMinutes( - 5 ) Subtract minutes. 5 dtmDelivery = dtmDelivery.AddDays( 1 ) Add day . 1 dtmDelivery = dtmDelivery.AddMinutes( 30 ) Add minutes. 30 dtmDelivery = dtmDelivery.AddHours( - 12 ) Subtract hours. 12 14.2 Date Variables Figure 14.3 Date methods that perform various calculations.

  8. Action Control Event/Method Application is run Label the application’s controls lblCurrentTime , lblDropOff , lblDeliveryTime FrmShippingTime Load Set range of possible drop off times dtpDropOff to any time in the current day Determine the shipment’s d elivery dtpDropOff time Display the shipment’s delivery lblLasVegasTime time dtpDropOff ValueChanged Determine the shipment’s delivery dtpDropOff time Display the shipment’s delivery lblLasVegasTime time tmrClock Tick Update and display the cur rent lblCurrentTime time DisplayDeliveryTime Determine the time the shipment’s dtpDropOff flight will depart Add three hours to determine the delivery time Display the delivery time lblLasVegasTime Figure 14.4 ACE table for the ap plication. Shipping Time 14.3 Building the Shipping Time Application: Design Elements

  9. 14.3 Building the Shipping Time Application: Design Elements

  10. Newly created GroupBox displaying the text Drop Off GroupBoxes 14.3 Building the Shipping Time Application: Design Elements Figure 14.5 GroupBox controls on the Shipping TimeForm. • Add a second Groupbox to contain drop off time

  11. Before clicking inside the GroupBox 14.3 Building the Shipping Time Application: Design Elements Figure 14.6 Adding a Label to a GroupBox. • Place a label inside the GroupBox by clicking the Label tab in the Toolbox

  12. DateTimePicker control before modification (note that the appearance is similar to a ComboBox) 14.3 Building the Shipping Time Application: Design Elements Figure 14.7 DateTimePicker control on the Form. • Add a DateTimePicker to the application by clicking the DateTimePickercontrol in the Toolbox

  13. Up-down arrows for DateTimePicker (note that the appearance is similar to a NumericUpDown control) 14.3 Building the Shipping Time Application: Design Elements Figure 14.8 CustomizedDateTimePicker control on the Form. • Set ShowUpDown property to True

  14. Timer control Component tray 14.3 Building the Shipping Time Application: Design Elements Figure 14.9 Timer control is displayed in the component tray.

  15. 14.4 Creating the Shipping Time Application: Inserting Code • Tick event handler • Date property Now retrieves current time • Format output • hh:mm:sstt

  16. Printing the current time 14.4 Creating the Shipping Time Application: Inserting Code Figure 14.10 Inserting code for a Tick event.

  17. 14.4 Creating the Shipping Time Application: Inserting Code • Load event handler • Date stored in dtmCurrentTime • FrmShippingTime_Load event handler • MinDate: earliest date allowed • MaxDate: latest date allowed

  18. Storing the current time in dtmCurrentTime 14.4 Creating the Shipping Time Application: Inserting Code Figure 14.11 Storing the current time.

  19. 14.4 Creating the Shipping Time Application: Inserting Code • MinDate property • Earliest value user can enter • Set to 12:00 AM • MaxDate property • Latest value user can enter • Seafood must remain fresh, so value will be set to one day after MinDate

  20. Setting the range of drop-off times 14.4 Creating the Shipping Time Application: Inserting Code Figure 14.12 Setting the MinDate and MaxDate properties.

  21. Displaying the delivery time 14.4 Creating the Shipping Time Application: Inserting Code Figure 14.13 Calling the DisplayDeliveryTime procedure.

  22. 14.4 Creating the Shipping Time Application: Inserting Code • Need to allow user to select a date • Application will calculate delivery time • ValueChanged event handler

  23. Calculating and displaying the delivery time 14.4 Creating the Shipping Time Application: Inserting Code Figure 14.14  Inserting code in the ValueChanged event handler.

  24. Determining the departure time Calculating the travel time Displaying the delivery time 14.4 Creating the Shipping Time Application: Inserting Code Figure 14.15 Calling the DepartureTimeprocedure.

  25. Declaring variables 14.4 Creating the Shipping Time Application: Inserting Code Figure 14.16  Inserting procedure DepartureTime into the application.

  26. Using the hour value stored in the DateTimePicker to determine departure time Noon departure time Noon (the next day) departure time Midnight departure time 14.4 Creating the Shipping Time Application: Inserting Code Figure 14.17 Determining the seafood shipment’s flight departure time.

  27. Returning the departure time 14.4 Creating the Shipping Time Application: Inserting Code Figure 14.18 Returning the flight departure time.

  28. Displaying the current time ShippingTime.vb(1 of 4)

  29. Setting the DateTimePicker’s minimum and maximum values ShippingTime.vb(2 of 4)

  30. Calculating and displaying the delivery time in Las Vegas Using a Select Case statement to determine departure time ShippingTime.vb(3 of 4)

  31. ShippingTime.vb(4 of 4)

More Related