1. Home
  2. Computing & Technology
  3. Visual Basic

Part 6: TripPlanner - A Complete WPF and XAML in Visual Basic
The AddADay Code and the System Download

By , About.com Guide

Nov 2 2008

Here's the AddADay code:

Partial Public Class AddADay
   Dim TripInformation As XDocument
   Private Sub AddADay_Loaded( _
      ByVal sender As Object, _
      ByVal e As System.Windows.RoutedEventArgs) _
      Handles Me.Loaded
      If Me.Tag = "A" Then
         AddADay() ' AddADay called through click
      Else
         ' AddADay called by double clicking date
         StayAtDate.Text = Me.Tag
         TripInformation = _
            XDocument.Load("TripInfo.xml")
         Dim StayAtElement = _
            From TripDate _
            In TripInformation...<TripDate> _
            Where TripDate = StayAtDate.Text
         StayAtDesc.Text = StayAtElement.@<StayAt>
         TransDesc.Text = StayAtElement.@<Trans>
         EventsDesc.Text = StayAtElement.@<Events>
      End If
   End Sub
   Private Sub ExitDesc_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.Windows.RoutedEventArgs) _
      Handles ExitDesc.Click
      Me.Close()
   End Sub
   Private Sub ContentChanged( _
      ByVal sender As System.Object, _
      ByVal e As System.Windows.RoutedEventArgs) _
      Handles StayAtDesc.LostFocus, _
            TransDesc.LostFocus, _
            EventsDesc.LostFocus
      TripInformation = XDocument.Load("TripInfo.xml")
      Dim StayAtElement = _
         From TripDate _
         In TripInformation...<TripDate> _
         Where TripDate = StayAtDate.Text
      Select Case e.Source.name
         Case "StayAtDesc"
            StayAtElement.@StayAt = StayAtDesc.Text
         Case "TransDesc"
            StayAtElement.@Trans = TransDesc.Text
         Case "EventsDesc"
            StayAtElement.@Events = EventsDesc.Text
      End Select
      TripInformation.Save("TripInfo.xml")
   End Sub
   Private Sub AddADay()
      TripInformation = XDocument.Load("TripInfo.xml")
      Dim myTripDates = _
         From tripdates _
         In TripInformation...<TripDate>
      Dim myTripDate = _
         From tripdate _
         In TripInformation...<TripDates>
      Dim LastDate As Date = _
         Date.Parse(myTripDates.Last().Value)
      Dim LastDateString = _
         Format(LastDate.AddDays(1), "MM/dd/yyyy")
      StayAtDate.Text = LastDateString
      myTripDate(0).Add( _
         <TripDate><%= LastDateString %></TripDate>)
      TripInformation.Save("TripInfo.xml")
   End Sub
End Class

The entire project can be downloaded here.

Explore Visual Basic
By Category
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Using VB.NET
  5. Part 6: TripPlanner - A Complete XAML and WPF Application

©2009 About.com, a part of The New York Times Company.

All rights reserved.