Heres an example of nested loops that acheives what you are trying to do:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim TotalFilledRooms As Integer = 0
Dim perc As Double
For i As Integer = 1 To 8
Dim response As Boolean = False
Dim filledRooms As Integer
While (Not response) Or (filledRooms < 0 Or filledRooms > 30)
response = Integer.TryParse(InputBox("How many rooms on floor " & i.ToString() & " are occupied?", "Enter number of occupied rooms"), filledRooms)
End While
perc = Math.Round((filledRooms / 30) * 100, 1)
TotalFilledRooms += filledRooms
Dim floor As String = "Floor " & i.ToString() & ": " & filledRooms.ToString() & "/30 " & perc.ToString() & "%"
lstFloors.Items.Add(floor)
Next
perc = Math.Round((TotalFilledRooms / 240) * 100, 1)
lblOccRooms.Text = TotalFilledRooms.ToString() & "/240"
lblOccPerc.Text = perc.ToString() & "%"
End Sub
The for loop ensures that 8 values are requested.
Theres some basic validation in the while loop, if the returned value cannot be parsed as an integer or the integer returned is outside the range 0-30 then the input window will reappear until a valid value is entered.
Reputation Points: 512
Solved Threads: 246
Nearly a Posting Virtuoso
Offline 1,260 posts
since Aug 2009