My code works but if data entered is more than the max number per floor (30) I can get a message box to show the data error, but I don't know how to stop calculating and displaying occupancy for the floor until I get a good number input.
I'm sure it's simple and if anyone can point me in the right direction I would appreciate it.
Private Sub btnReport_Click(sender As System.Object, e As System.EventArgs) Handles btnReport.Click
Const dblTOTAL_ROOMS As Double = 240 ' total number of rooms in hotel
Const dblFLOOR_ROOMS As Double = 30 ' total number of rooms per floor
Dim intFloorCount As Integer ' loop counter
Dim dblRooms, dblTotalRooms As Double ' to hold rooms per floor input and accumulator for total rooms
Dim strInput As String ' to hold user input
Dim decFloorOccupancy, decTotalOccupancy As Decimal ' to hold floor occupancy and total occupancy percentages
For intFloorCount = 1 To 8
'prompt user for number of rooms occupied for the floor
strInput = InputBox("Enter # Rooms Occupied on Floor # " & intFloorCount.ToString())
'convert the input to to a double
Double.TryParse(strInput, dblRooms)
'compute the floor occupancy
decFloorOccupancy = dblRooms / dblFLOOR_ROOMS
'create a string to display floor occupancy
lstFloors.Items.Add("Floor " & intFloorCount.ToString() & " Rooms Occupied: " &
dblRooms.ToString() & " " & "Occupancy Rate is " & decFloorOccupancy.ToString("p"))
'add the rooms to the accumulator
dblTotalRooms += dblRooms
Next
'calculate the total occupancy
decTotalOccupancy = dblTotalRooms / dblTOTAL_ROOMS
'display total rooms ococupied and total occupancy
lblRooms.Text = dblTotalRooms.ToString()
lblTotalOccupancy.Text = decTotalOccupancy.ToString("p")
End Sub

New Topic/Question
Reply



MultiQuote



|