Guest User

Untitled

a guest
Nov 27th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.99 KB | None | 0 0
  1. ' Program Name: Galaxy Hotel Occupancy Calculator
  2. ' Developer:
  3. ' Date: November 26, 2014
  4. ' Purpose: To calculate the occupancy rate, total rooms,
  5. ' total rooms sold, and total rooms available
  6. ' of the Galaxy Hotel.
  7.  
  8. Public Class frmOccupancyRateCalculator
  9.  
  10. Private Sub frmOccupancyRateCalculator_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  11. ' This script executes when the program is laoded into memory.
  12. ' It clears the Room Sales and Rooms Available ListBoxes of all items.
  13.  
  14. lstRoomsSold.Items.Clear()
  15. lstRoomsAvailable.Items.Clear()
  16.  
  17. End Sub
  18.  
  19. Private Sub btnEnterRoomSales_Click(sender As Object, e As EventArgs) Handles btnEnterRoomSales.Click
  20. ' This script is executed when the user taps or clicks the Enter Room Sales button.
  21. ' It displays an inputbox for the user to enter rooms sold and rooms available for
  22. ' one floor at a time. It then checks the input for validity, then calculates the
  23. ' total number of rooms, total rooms sold, total rooms available, and occupancy rate.
  24. ' It then displays the results in the Result label then disables the Enter Room Sales button.
  25.  
  26. ' Declare the arithimetic and message variables.
  27. Dim intRoomsSold As Integer
  28. Dim intRoomsAvailable As Integer
  29. Dim intTotalRooms As Integer
  30. Dim intTotalRoomsSold As Integer
  31. Dim intTotalRoomsAvailable As Integer
  32. Dim intRoomsSoldNumberOfEntries As Integer = 1
  33. Dim intRoomsAvailableNumberOfEntries As Integer = 1
  34. Dim intNumberOfEntries As Integer = 1
  35. Dim intMaxNumberOfEntries As Integer = 7
  36. Dim decOccupancyRate As Decimal
  37. Dim strRoomsSold As String
  38. Dim strRoomsSoldInputMessage As String = "Enter the number of rooms sold for floor #"
  39. Dim strRoomsSoldInputHeading As String = "Enter Rooms Sold"
  40. Dim strRoomsSoldNormalMessage As String = "Enter the number of rooms sold for floor #"
  41. Dim strRoomsSoldNonNumericError As String = "Error - Non-Numeric value entered. Please enter a whole number of rooms sold for floor #"
  42. Dim strRoomsSoldNegativeError As String = "Error - Negative number entered. Please enter a whole number greater than zero of rooms sold for floor #"
  43. Dim strRoomsSoldDecimalError As String = "Error - Decimal number entered. Plerase enter a whole number of rooms sold for floor #"
  44. Dim strRoomsAvailable As String
  45. Dim strRoomsAvailableInputMessage As String = "Enter the number of rooms available for floor #"
  46. Dim strRoomsAvailableInputHeading As String = "Enter Rooms Available"
  47. Dim strRoomsAvailableNormalMessage As String = "Enter the number of rooms available for floor #"
  48. Dim strRoomsAvailableNonNumericError As String = "Error - Non-Numeric value entered. Please enter a whole number of rooms available for floor #"
  49. Dim strRoomsAvailableNegativeError As String = "Error - Negative number entered. Please enter a whole number greater than zero of rooms available for floor #"
  50. Dim strRoomsAvailableDecimalError As String = "Error - Decimal number entered. Plerase enter a whole number of rooms available for floor #"
  51. Dim strCancelClicked As String = ""
  52.  
  53. ' Define the RoomsSoldInputMessage variables
  54. strRoomsSold = InputBox(strRoomsSoldInputMessage & intRoomsSoldNumberOfEntries, strRoomsSoldInputHeading, " ")
  55.  
  56. ' Loop to iterate until hours of travel are entered for all days of travel
  57. Do Until intRoomsSoldNumberOfEntries > intMaxNumberOfEntries
  58.  
  59. ' Is the input numeric?
  60. If IsNumeric(strRoomsSold) Then
  61. intRoomsSold = Convert.ToDecimal(strRoomsSold)
  62.  
  63. ' Is the input greater or equal to 0?
  64. If intRoomsSold >= 0 Then
  65.  
  66. ' Is the number of rooms sold a whole number?
  67. 'If intRoomsSold Mod 1 = 0 Then
  68.  
  69. intTotalRoomsSold += intRoomsSold
  70. lstRoomsSold.Items.Add(intRoomsSold)
  71. intRoomsSoldNumberOfEntries += 1
  72. intRoomsSold = 0
  73. strRoomsSoldInputMessage = strRoomsSoldNormalMessage
  74.  
  75. ' Display decimal error message
  76. 'Else
  77. 'strRoomsSoldInputMessage = strRoomsSoldDecimalError
  78. 'End If
  79.  
  80. ' Display negative number error message
  81. Else
  82. strRoomsSoldInputMessage = strRoomsSoldNegativeError
  83.  
  84. End If
  85.  
  86. ' Display non-numeric error message
  87. Else
  88. strRoomsSoldInputMessage = strRoomsSoldNonNumericError
  89.  
  90. End If
  91.  
  92. ' Is the number of entries less than or equal to the maximum?
  93. If intRoomsSoldNumberOfEntries <= intMaxNumberOfEntries Then
  94. strRoomsSoldInputMessage = InputBox(strRoomsSoldInputMessage & intRoomsSoldNumberOfEntries, strRoomsSoldInputHeading, " ")
  95.  
  96. End If
  97.  
  98. Loop
  99.  
  100.  
  101. ' Define the RoomsAvailableInputMessage variable
  102. strRoomsAvailable = InputBox(strRoomsAvailableInputMessage & intRoomsAvailableNumberOfEntries, strRoomsAvailableInputHeading, " ")
  103.  
  104. Do Until intRoomsAvailableNumberOfEntries > intMaxNumberOfEntries
  105.  
  106. ' Is the input numeric?
  107. If IsNumeric(strRoomsAvailable) Then
  108. intRoomsAvailable = Convert.ToDecimal(strRoomsAvailable)
  109.  
  110. ' Is the input greater or equal to 0?
  111. If intRoomsAvailable >= 0 Then
  112.  
  113. ' Is the number of rooms sold a whole number?
  114. 'If intRoomsAvailable Mod 1 = 0 Then
  115.  
  116. intTotalRoomsAvailable += intRoomsAvailable
  117. lstRoomsAvailable.Items.Add(intRoomsAvailable)
  118. intRoomsAvailableNumberOfEntries += 1
  119. intRoomsAvailable = 0
  120. strRoomsAvailableInputMessage = strRoomsAvailableNormalMessage
  121.  
  122. ' Is the number of entries equal to the maximum number of entries?
  123. If intRoomsAvailableNumberOfEntries = intMaxNumberOfEntries Then
  124. intNumberOfEntries += 1
  125. End If
  126.  
  127. ' Display decimal error message
  128. 'Else
  129. ' strRoomsAvailableInputMessage = strRoomsAvailableDecimalError
  130. ' End If
  131.  
  132. ' Display negative number error message
  133. Else
  134. strRoomsAvailableInputMessage = strRoomsAvailableNegativeError
  135.  
  136. End If
  137.  
  138. ' Display non-numeric error message
  139. Else
  140. strRoomsAvailableInputMessage = strRoomsAvailableNonNumericError
  141.  
  142. End If
  143.  
  144. ' Is the number of entries less than or equal to the maximum?
  145. If intRoomsAvailableNumberOfEntries <= intMaxNumberOfEntries Then
  146. strRoomsAvailableInputMessage = InputBox(strRoomsAvailableInputMessage & intRoomsAvailableNumberOfEntries, strRoomsAvailableInputHeading, " ")
  147.  
  148. End If
  149.  
  150. Loop
  151.  
  152. ' Is the number of rooms sold entries greater than 1?
  153. If intNumberOfEntries > 1 Then
  154.  
  155. ' Display result label and totals
  156.  
  157. intTotalRooms = intTotalRoomsSold + intTotalRoomsAvailable
  158. decOccupancyRate = intTotalRoomsSold / intTotalRooms
  159. lblResult.Visible = True
  160. lblResult.Text = intTotalRooms & vbNewLine & intTotalRoomsSold & vbNewLine & intTotalRoomsAvailable & vbNewLine & vbNewLine & decOccupancyRate.ToString("P")
  161.  
  162. ' Disable the Enter Room Sales button
  163. btnEnterRoomSales.Enabled = False
  164.  
  165. ' Display error message for no values entered
  166. Else
  167. MsgBox("No Rooms Sold/Available value entered")
  168.  
  169. End If
  170.  
  171. End Sub
  172.  
  173. Private Sub mnuClear_Click(sender As Object, e As EventArgs) Handles mnuClear.Click
  174. ' This script is executed when the user taps or clicks the Clear menu item.
  175. ' It clears the Room Sales and Rooms Available ListBoxes, hides the Result label,
  176. ' enables the Enter Room Sales button.
  177.  
  178. lstRoomsSold.Items.Clear()
  179. lstRoomsAvailable.Items.Clear()
  180. lblResult.Visible = False
  181. btnEnterRoomSales.Enabled = True
  182.  
  183. End Sub
  184.  
  185. Private Sub mnuExit_Click(sender As Object, e As EventArgs) Handles mnuExit.Click
  186. ' This script is executed when the user taps or clicks the Exit menu item.
  187. ' The window is closed and the program is terminated.
  188.  
  189. Close()
  190.  
  191. End Sub
  192. End Class
Add Comment
Please, Sign In to add comment