I have been working on a project that requires arrival date, departure date, number of nights, price per night and total price. I have everything working somewhat but can not seem to figure out how to get the last three items to display in the text boxes instead of a message box. What am I doing wrong? Below is what I have so far:
Imports System.Text
Partial Public Class frmReservations
Inherits Form
Const pricePerNight As Integer = 115
Public Sub New()
InitializeComponent()
End Sub
Private Sub frmReservations_Load(sender As Object, e As EventArgs)
txtDepart.Text = DateTime.Today.ToString("d")
txtArrive.Text = DateTime.Today.AddDays(3).ToString("d")
End Sub
Private Sub btnCalculate_Click(sender As System.Object, e As System.EventArgs) Handles btnCalculate.Click
Dim dtDepart As DateTime
Dim dtArrive As DateTime
If String.IsNullOrEmpty(txtDepart.Text) OrElse Not DateTime.TryParse(txtDepart.Text, dtDepart) Then
MessageBox.Show("Invalid departure date!")
Return
End If
If String.IsNullOrEmpty(txtArrive.Text) OrElse Not DateTime.TryParse(txtArrive.Text, dtArrive) Then
MessageBox.Show("Invalid arrival date!")
Return
End If
dtDepart = dtDepart.[Date]
dtArrive = dtArrive.[Date]
If dtDepart < DateTime.Today Then
MessageBox.Show("The departure date cannot be before today")
Return
End If
If dtArrive > dtDepart Then
MessageBox.Show("The departure date cannot be before the departure date")
Return
End If
Dim dtUpperBoundary As DateTime = DateTime.Today.AddDays(365 * 5)
If dtDepart > dtUpperBoundary Then
MessageBox.Show("The departure date is more than 5 years in the future")
Return
End If
If dtArrive > dtUpperBoundary Then
MessageBox.Show("The arrival date is more than 5 years in the future")
Return
End If
If dtArrive = dtDepart Then
MessageBox.Show("You cannot depart and arrive on the same date")
Return
End If
'At this point the dates should be good
Dim duration As Integer = Convert.ToInt32(Math.Ceiling(Math.Abs(dtArrive.Subtract(dtDepart).TotalDays))) + 1
Dim price As Integer = duration * pricePerNight
Dim sNumberOfDays As String = duration.ToString()
Dim sArrivalDate As String = dtArrive.ToString("d")
Dim sDeparture As String = dtDepart.ToString("d")
Dim sTotalPrice As String = price.ToString("C2")
Dim sb As New StringBuilder()
sb.AppendLine("Number of days: " + sNumberOfDays)
sb.AppendLine("Arrival Date: " + sArrivalDate)
sb.AppendLine("Departure Date: " + sDeparture)
sb.AppendLine("Total Price: " + sTotalPrice)
MessageBox.Show(sb.ToString())
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class