Click here to Skip to main content
15,442,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is my code at the moment. Can you please tell me what more to add to show total cost in a label when user selects random radio buttons and checkboxes?

windows application that helps the receptionist generate a quote for a hotel room sale for a family’s one night stay in the hotel. You have to choose an appropriate name for your application. The hotel has 3 types of rooms only and provides buffet breakfast and dinner for a fee. Apart from internet, entertainment and spa services, all other hotel amenities are free of charge.

Room Type = (radiobuttons) a.luxury $210 b. Superior $150 c. Standard $110 Meals (checkboxes) a. Breakfast $40 b. Dinner$60

Amenities (checkboxes) a. Internet$10 b. Entertainment – Pay movies$20 c. Spa Services$50 all these have constant prices ............................. the code below is what i have done till now. can you please help me out on how to display the total cost in the label
VB.NET
Public Class frmThePearlResortFiji

Private Sub frmThePearlResortFiji_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    lblDate.Text = Date.Now
End Sub

Private Sub btnTotalCost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTotalCost.Click

    lblTotalCost.Text = "YOU HAVE ORDERED:" & vbNewLine

    lblTotalCost.Text = lblTotalCost.Text & "ROOM TYPE" & vbNewLine & "--------" & vbNewLine

    If radLuxury.Checked Then
        lblTotalCost.Text = lblTotalCost.Text & "Luxury = $210" & vbNewLine
    ElseIf radSuperior.Checked Then
        lblTotalCost.Text = lblTotalCost.Text & "Superior = $150" & vbNewLine
    Else
        lblTotalCost.Text = lblTotalCost.Text & "Standard = $110" & vbNewLine
    End If

    lblTotalCost.Text = lblTotalCost.Text & vbNewLine & "MEAL OPTIONS" & vbNewLine & "--------" & vbNewLine

    If chkBufferBreakfast.Checked Then
        lblTotalCost.Text = lblTotalCost.Text & "Buffer Breakfast = $40" & vbNewLine
    End If
    If chkBufferDinner.Checked Then
        lblTotalCost.Text = lblTotalCost.Text & "Buffer Dinner = $60" & vbNewLine
    End If

    lblTotalCost.Text = lblTotalCost.Text & vbNewLine & "AMENITIES" & vbNewLine & "--------" & vbNewLine

    If chkInternet.Checked Then
        lblTotalCost.Text = lblTotalCost.Text & "Internet = $10" & vbNewLine
    End If
    If chkEntertainment.Checked Then
        lblTotalCost.Text = lblTotalCost.Text & "Entertainment = $20" & vbNewLine
    End If
    If chkSpaServices.Checked Then
        lblTotalCost.Text = lblTotalCost.Text & "Spa Services = $50" & vbNewLine
    End If

    lblTotalCost.Text = decLuxury + decSuperior + decStandard


End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
    Me.Close()
End Sub

Private Sub radLuxury_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radLuxury.CheckedChanged
    picSuperior.Visible = False
    picStandard.Visible = False
    picLuxury.Visible = True

End Sub

Private Sub radSuperior_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radSuperior.CheckedChanged
    picLuxury.Visible = False
    picStandard.Visible = False
    picSuperior.Visible = True
End Sub

Private Sub radStandard_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radStandard.CheckedChanged
    picSuperior.Visible = False
    picLuxury.Visible = False
    picStandard.Visible = True
End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
    lblTotalCost.Text = ""
    radLuxury.Checked = False
    radSuperior.Checked = False
    radStandard.Checked = False

    chkBufferBreakfast.Checked = False
    chkBufferDinner.Checked = False

    chkEntertainment.Checked = False
    chkInternet.Checked = False
    chkSpaServices.Checked = False

    picLuxury.Image = Nothing
    picSuperior.Image = Nothing
    picStandard.Image = Nothing

End Sub
End Class


What I have tried:

i have done till here . can you please guide me on what to add to show the total cost in the label that is lblTotalCost
Posted
Updated 29-Sep-20 7:26am
v2

That's some pretty jumbled code you have there.

Go back a couple of stages, and re-think how you are doing this.
I'd set up an ChargeableItem class containing three properies:
Description    String
Cost           Decimal
Currency       String
And then override the ToString method for that class to return a human readable version:
Public Overrides Function ToString() As String
    Return $"{Description} - {Currency}{Cost}"
End Function
If you set the Tag property of each RadioButton and CheckBox to an instance of the class, you can then access that when they are selected, and your values are ready for you, with no further processing required.
You can even automate the display by using a Panel to hold each "option group" and adding buttons or Checkboxes to that when your form is constructed from a Collection of the class.

Doing it that way means you can hold the "pricing data" in a file or database instead of "hard coding" it into your app - and that means when prices or availability changes, you can reflect that in your app a lot more easily. You can also cope with different currencies very simply to allow foreign visitors to understand costs in their own currency!
 
Share this answer
 
Comments
Ralf Meier 30-Sep-20 17:23pm     CRLF
Hi Griff, I stumbled into your answer to this question. I have also a Solution to this which is in fact very much easier (und much more understandable) than this approach - but now I`m much more interessted in yours. I don't have understood the suggestion from you - would you be so kind to explain it for me because perhaps this could be an approach which makes my kind of work a little easier ... Cheers Ralf

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900