dcsimg
Results 1 to 2 of 2

Thread: Hotel App Vacancy/Occupany problems

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2017
    Posts
    35

    Hotel App Vacancy/Occupany problems

    Hello, working on this program for class. It states that it should ask 2 questions about each floor. (How many rooms are occupied on the floor? How many rooms are vacant on the floor?)

    I have set the parameters for values at (7 floors, 30 rooms per floor.)

    Now here is where I am getting thrown. How can I get the program to recognize the value entered for vacancies so that I will end up with an even 30 rooms per floor each time? Now I am able to enter up to 30 for each vacancy/occupancy and can end up with up to 60 rooms per floor.

    Is there a way for the program to acknowledge the first value entered so that the precise value can be entered after?

    Here is what I am working with so far. Thanks.

    Code:
    Public Class frmGalaxyHotel
    
        Private decTotalOccupied As Decimal
        Private decTotalVacant As Decimal
        Const decTotalRooms As Decimal = 210
    
    
    
    
        Private Sub frmGalaxyHotel_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            lstOccupied.Items.Clear()
            lstVacant.Items.Clear()
            lblTotalRooms.Visible = False
            lblTotalVacant.Visible = False
            lblTotalOccupied.Visible = False
            lblOccupanyRate.Visible = False
            btnOccupancy.Enabled = False
    
        End Sub
    
        Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnVacancy.Click
            'The button calculate click event accepts and displays up to 7 values each of occupied
            'and vacant rooms. Then calcuates and displays results
    
            Dim strRoomsVacant As String
            Dim decRoomsVacant As String
            Dim strInputMessage As String = "Enter the number of vacant rooms on floor # "
            Dim strInputHeading As String = "Galaxy Hotel"
            Dim strVacancyMessage As String = "Enter the number of vacant rooms on floor # "
            Dim strNonNumericError As String = "ERROR- Enter a numeric value only"
            Dim strNegativeError As String = "ERROR- Enter a positive numeric value. There are 30 rooms per floor. "
    
            'Loop Variables
            Dim strCancelClicked As String = ""
            Dim intNumberOfEntries As Integer = 1
            Dim intMaxNumberOfEntries As Integer = 7
    
            strRoomsVacant = InputBox(strInputMessage & intNumberOfEntries, strInputHeading, " ")
    
            Do Until intNumberOfEntries > intMaxNumberOfEntries Or strRoomsVacant = strCancelClicked
                If IsNumeric(strRoomsVacant) Then
                    decRoomsVacant = Convert.ToDecimal(strRoomsVacant)
                    If decRoomsVacant > 0 And decRoomsVacant <= 30 Then
                        lstVacant.Items.Add(decRoomsVacant)
                        decTotalVacant += decRoomsVacant
                        intNumberOfEntries += 1
                        strInputMessage = strVacancyMessage
                    Else
                        strInputMessage = strNegativeError
                    End If
                Else
                    strInputMessage = strNonNumericError
                End If
    
                If intNumberOfEntries <= intMaxNumberOfEntries Then
                    strRoomsVacant = InputBox(strInputMessage & intNumberOfEntries, strInputHeading, " ")
                End If
            Loop
    
            btnOccupancy.Enabled = True
            btnVacancy.Enabled = False
    
        End Sub
    
        Private Sub mnuClear_Click(sender As Object, e As EventArgs) Handles mnuClear.Click
    
            lstOccupied.Items.Clear()
            lstVacant.Items.Clear()
            lblRooms.Visible = False
            lblVacant.Visible = False
            lblOccupied.Visible = False
            lblRate.Visible = False
            lblTotalRooms.Visible = False
            lblTotalVacant.Visible = False
            lblTotalOccupied.Visible = False
            lblOccupanyRate.Visible = False
            btnOccupancy.Enabled = False
    
        End Sub
    
        Private Sub btnOccupancy_Click(sender As Object, e As EventArgs) Handles btnOccupancy.Click
    
            Dim strRoomsOccupied As String
            Dim decRoomsOccupied As Decimal
            Dim decOccupancyRate As Decimal = 0
            Dim strInputMessage As String = "Enter the number of occupied rooms on floor # "
            Dim strInputHeading As String = "Galaxy Hotel"
            Dim strOccupancyMessage As String = "Enter the number of occupied rooms on floor # "
            Dim strNonNumericError As String = "ERROR- Enter a numeric value for floor # "
            Dim strNegativeError As String = "ERROR- Enter a positive numeric value. There are 30 rooms per floor. "
    
    
            'Loop Variables
            Dim strCancelClicked As String = ""
            Dim intNumberOfEntries As Integer = 1
            Dim intMaxNumberOfEntries As Integer = 7
    
            strRoomsOccupied = InputBox(strInputMessage & intNumberOfEntries, strInputHeading, " ")
    
            Do Until intNumberOfEntries > intMaxNumberOfEntries Or strRoomsOccupied = strCancelClicked
                If IsNumeric(strRoomsOccupied) Then
                    decRoomsOccupied = Convert.ToDecimal(strRoomsOccupied)
                    If decRoomsOccupied > 0 And decRoomsOccupied <= 30 Then
                        lstOccupied.Items.Add(decRoomsOccupied)
                        decTotalOccupied += decRoomsOccupied
                        intNumberOfEntries += 1
                        strInputMessage = strOccupancyMessage
                    Else
                        strInputMessage = strNegativeError
                    End If
                Else
                    strInputMessage = strNonNumericError
                End If
    
                If intNumberOfEntries <= intMaxNumberOfEntries Then
                    strRoomsOccupied = InputBox(strInputMessage & intNumberOfEntries, strInputHeading, " ")
                End If
            Loop
    
            'Calculates and displays occupany rate
            If intNumberOfEntries > 1 Then
                lblOccupanyRate.Visible = True
                decOccupancyRate = decTotalVacant / decTotalOccupied
                lblOccupanyRate.Text = decOccupancyRate.ToString("P")
            Else
                MsgBox("Please Enter A Numeric Value")
            End If
    
            'Calculates and displays total vacant rooms
            lblTotalVacant.Visible = True
            lblTotalVacant.Text = decTotalVacant
    
            'Calculates and displays total occupied rooms
            lblTotalOccupied.Visible = True
            lblTotalOccupied.Text = decTotalOccupied
    
            'Displays total # of rooms in hotel
            lblTotalRooms.Visible = True
            lblTotalRooms.Text = decTotalRooms
    
    
        End Sub
    End Class

  2. #2
    Fanatic Member
    Join Date
    Feb 2013
    Posts
    911

    Re: Hotel App Vacancy/Occupany problems

    Hi, im just going down the code you gave us and came across this..... what is this 'Surposed' to be doing?

    Code:
    strRoomsVacant = InputBox(strInputMessage & intNumberOfEntries, strInputHeading, " ")
    
            Do Until intNumberOfEntries > intMaxNumberOfEntries Or strRoomsVacant = strCancelClicked
                If IsNumeric(strRoomsVacant) Then
                    decRoomsVacant = Convert.ToDecimal(strRoomsVacant)
                    If decRoomsVacant > 0 And decRoomsVacant <= 30 Then
                        lstVacant.Items.Add(decRoomsVacant)
                        decTotalVacant += decRoomsVacant
                        intNumberOfEntries += 1
                        strInputMessage = strVacancyMessage
                    Else
                        strInputMessage = strNegativeError
                    End If
                Else
                    strInputMessage = strNonNumericError
                End If
    
                If intNumberOfEntries <= intMaxNumberOfEntries Then
                    strRoomsVacant = InputBox(strInputMessage & intNumberOfEntries, strInputHeading, " ")
                End If
            Loop
    i am guessing that you want the input box to show up several times (once for each floor) so that you can get the values you need?

    if so then you need to move your input box code 'INTO' the loop here so it pops up each loop iteration
    Yes!!!
    Working from home is so much better than working in an office...
    Nothing can beat the combined stress of getting your work done on time whilst
    1. one toddler keeps pressing your AVR's power button
    2. one baby keeps crying for milk
    3. one child keeps running in and out of the house screaming and shouting
    4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
    5. working at 1 O'clock in the morning because nobody is awake at that time
    6. being grossly underpaid for all your hard work


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width