Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' Program Name: Galaxy Hotel Occupancy Calculator
- ' Developer:
- ' Date: November 26, 2014
- ' Purpose: To calculate the occupancy rate, total rooms,
- ' total rooms sold, and total rooms available
- ' of the Galaxy Hotel.
- Public Class frmOccupancyRateCalculator
- Private Sub frmOccupancyRateCalculator_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- ' This script executes when the program is laoded into memory.
- ' It clears the Room Sales and Rooms Available ListBoxes of all items.
- lstRoomsSold.Items.Clear()
- lstRoomsAvailable.Items.Clear()
- End Sub
- Private Sub btnEnterRoomSales_Click(sender As Object, e As EventArgs) Handles btnEnterRoomSales.Click
- ' This script is executed when the user taps or clicks the Enter Room Sales button.
- ' It displays an inputbox for the user to enter rooms sold and rooms available for
- ' one floor at a time. It then checks the input for validity, then calculates the
- ' total number of rooms, total rooms sold, total rooms available, and occupancy rate.
- ' It then displays the results in the Result label then disables the Enter Room Sales button.
- ' Declare the arithimetic and message variables.
- Dim intRoomsSold As Integer
- Dim intRoomsAvailable As Integer
- Dim intTotalRooms As Integer
- Dim intTotalRoomsSold As Integer
- Dim intTotalRoomsAvailable As Integer
- Dim intRoomsSoldNumberOfEntries As Integer = 1
- Dim intRoomsAvailableNumberOfEntries As Integer = 1
- Dim intNumberOfEntries As Integer = 1
- Dim intMaxNumberOfEntries As Integer = 7
- Dim decOccupancyRate As Decimal
- Dim strRoomsSold As String
- Dim strRoomsSoldInputMessage As String = "Enter the number of rooms sold for floor #"
- Dim strRoomsSoldInputHeading As String = "Enter Rooms Sold"
- Dim strRoomsSoldNormalMessage As String = "Enter the number of rooms sold for floor #"
- Dim strRoomsSoldNonNumericError As String = "Error - Non-Numeric value entered. Please enter a whole number of rooms sold for floor #"
- Dim strRoomsSoldNegativeError As String = "Error - Negative number entered. Please enter a whole number greater than zero of rooms sold for floor #"
- Dim strRoomsSoldDecimalError As String = "Error - Decimal number entered. Plerase enter a whole number of rooms sold for floor #"
- Dim strRoomsAvailable As String
- Dim strRoomsAvailableInputMessage As String = "Enter the number of rooms available for floor #"
- Dim strRoomsAvailableInputHeading As String = "Enter Rooms Available"
- Dim strRoomsAvailableNormalMessage As String = "Enter the number of rooms available for floor #"
- Dim strRoomsAvailableNonNumericError As String = "Error - Non-Numeric value entered. Please enter a whole number of rooms available for floor #"
- Dim strRoomsAvailableNegativeError As String = "Error - Negative number entered. Please enter a whole number greater than zero of rooms available for floor #"
- Dim strRoomsAvailableDecimalError As String = "Error - Decimal number entered. Plerase enter a whole number of rooms available for floor #"
- Dim strCancelClicked As String = ""
- ' Define the RoomsSoldInputMessage variables
- strRoomsSold = InputBox(strRoomsSoldInputMessage & intRoomsSoldNumberOfEntries, strRoomsSoldInputHeading, " ")
- ' Loop to iterate until hours of travel are entered for all days of travel
- Do Until intRoomsSoldNumberOfEntries > intMaxNumberOfEntries
- ' Is the input numeric?
- If IsNumeric(strRoomsSold) Then
- intRoomsSold = Convert.ToDecimal(strRoomsSold)
- ' Is the input greater or equal to 0?
- If intRoomsSold >= 0 Then
- ' Is the number of rooms sold a whole number?
- 'If intRoomsSold Mod 1 = 0 Then
- intTotalRoomsSold += intRoomsSold
- lstRoomsSold.Items.Add(intRoomsSold)
- intRoomsSoldNumberOfEntries += 1
- intRoomsSold = 0
- strRoomsSoldInputMessage = strRoomsSoldNormalMessage
- ' Display decimal error message
- 'Else
- 'strRoomsSoldInputMessage = strRoomsSoldDecimalError
- 'End If
- ' Display negative number error message
- Else
- strRoomsSoldInputMessage = strRoomsSoldNegativeError
- End If
- ' Display non-numeric error message
- Else
- strRoomsSoldInputMessage = strRoomsSoldNonNumericError
- End If
- ' Is the number of entries less than or equal to the maximum?
- If intRoomsSoldNumberOfEntries <= intMaxNumberOfEntries Then
- strRoomsSoldInputMessage = InputBox(strRoomsSoldInputMessage & intRoomsSoldNumberOfEntries, strRoomsSoldInputHeading, " ")
- End If
- Loop
- ' Define the RoomsAvailableInputMessage variable
- strRoomsAvailable = InputBox(strRoomsAvailableInputMessage & intRoomsAvailableNumberOfEntries, strRoomsAvailableInputHeading, " ")
- Do Until intRoomsAvailableNumberOfEntries > intMaxNumberOfEntries
- ' Is the input numeric?
- If IsNumeric(strRoomsAvailable) Then
- intRoomsAvailable = Convert.ToDecimal(strRoomsAvailable)
- ' Is the input greater or equal to 0?
- If intRoomsAvailable >= 0 Then
- ' Is the number of rooms sold a whole number?
- 'If intRoomsAvailable Mod 1 = 0 Then
- intTotalRoomsAvailable += intRoomsAvailable
- lstRoomsAvailable.Items.Add(intRoomsAvailable)
- intRoomsAvailableNumberOfEntries += 1
- intRoomsAvailable = 0
- strRoomsAvailableInputMessage = strRoomsAvailableNormalMessage
- ' Is the number of entries equal to the maximum number of entries?
- If intRoomsAvailableNumberOfEntries = intMaxNumberOfEntries Then
- intNumberOfEntries += 1
- End If
- ' Display decimal error message
- 'Else
- ' strRoomsAvailableInputMessage = strRoomsAvailableDecimalError
- ' End If
- ' Display negative number error message
- Else
- strRoomsAvailableInputMessage = strRoomsAvailableNegativeError
- End If
- ' Display non-numeric error message
- Else
- strRoomsAvailableInputMessage = strRoomsAvailableNonNumericError
- End If
- ' Is the number of entries less than or equal to the maximum?
- If intRoomsAvailableNumberOfEntries <= intMaxNumberOfEntries Then
- strRoomsAvailableInputMessage = InputBox(strRoomsAvailableInputMessage & intRoomsAvailableNumberOfEntries, strRoomsAvailableInputHeading, " ")
- End If
- Loop
- ' Is the number of rooms sold entries greater than 1?
- If intNumberOfEntries > 1 Then
- ' Display result label and totals
- intTotalRooms = intTotalRoomsSold + intTotalRoomsAvailable
- decOccupancyRate = intTotalRoomsSold / intTotalRooms
- lblResult.Visible = True
- lblResult.Text = intTotalRooms & vbNewLine & intTotalRoomsSold & vbNewLine & intTotalRoomsAvailable & vbNewLine & vbNewLine & decOccupancyRate.ToString("P")
- ' Disable the Enter Room Sales button
- btnEnterRoomSales.Enabled = False
- ' Display error message for no values entered
- Else
- MsgBox("No Rooms Sold/Available value entered")
- End If
- End Sub
- Private Sub mnuClear_Click(sender As Object, e As EventArgs) Handles mnuClear.Click
- ' This script is executed when the user taps or clicks the Clear menu item.
- ' It clears the Room Sales and Rooms Available ListBoxes, hides the Result label,
- ' enables the Enter Room Sales button.
- lstRoomsSold.Items.Clear()
- lstRoomsAvailable.Items.Clear()
- lblResult.Visible = False
- btnEnterRoomSales.Enabled = True
- End Sub
- Private Sub mnuExit_Click(sender As Object, e As EventArgs) Handles mnuExit.Click
- ' This script is executed when the user taps or clicks the Exit menu item.
- ' The window is closed and the program is terminated.
- Close()
- End Sub
- End Class
Add Comment
Please, Sign In to add comment