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

If you have the textboxes on your form, you have to use the Text property of the Textbox.
Example: myTextBx.Text = sTotalPrice;

I have tried that before unless I am placing incorrectly, would you be willing to show placement example within the code provided? Say for total price.

To show in a textbox instead of messagebox try this:

    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)
    'Make sure the multiline property on the textbox is set to true, otherwise only the first line will show up.
    Textbox1.Text = sb.ToString()

To put each one in a different textbox try this

    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")

    'The names of the textboxes is just an example, rename yours to match or change the name in the code up to you.

    txtNumDays.Text = "Number of days: " + sNumberOfDays
    txtArrivalDate.Text = "Arrival Date: " + sArrivalDate
    txtDepDate.Text = "Departure Date: " + sDeparture
    txtTotalPrice.Text = "Total Price: " + sTotalPrice

Thank you both for the assistance, I swear I tried adding them there before, sorry, rather new to this and have been getting frustrated with some long nights of learning. Thanks again.

I have one final question on this one, the depart date is supposed to revert to only three days past the arrive date, according to the text I have I thought this would work:

Private Sub frmReservations_Load(sender As Object, e As EventArgs)
        txtDepart.Text = DateTime.Today.ToString("d")
        txtArrive.Text = DateTime.Today.AddDays(3).ToString("d")

But it is not changing the depart date as desired. Any suggestions on what I am doing wrong here?

Your code puts arrive date 3 days after depart date, try swapping them.

yeah tried that, still doesn't change the date that is displayed. Guessing my coding is wrong, have tried other combinations of codes either get an error or just doesn't change the depart date.

I figured everthing out, much thanks to those that participated, very appreciative!

Glad it's worked out for you. Please remember to mark this solved thanks

commented: Always great effort! +14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.