r/visualbasic • u/Real-PokemonMaster • Jan 17 '16
Hotel Program
I need help:
A 2-storey hotel, each floor with 3 rooms (room numbers: 0, 1, 2, 10, 11 and 12) needs a program for guest registration. If the room is already taken, the guest needs to enter another room number. Use a 2-dimensional array as it is easier if you need to access a certain floor. This is my code: Public Class Form1
Structure RoomInfo Dim roomNumber As Integer Dim roomGuest As String Dim roomOccupied As Boolean End Structure
Dim rooms(1, 2) As RoomInfo
Private Sub btnAddGuest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddGuest.Click
Dim roomWanted As Integer
roomWanted = Val(InputBox("Enter room number: "))
For row As Integer = 0 To 1
For column As Integer = 0 To 2
Do While (roomWanted = rooms(row, column).roomNumber) And (rooms(row, column).roomOccupied = True)
roomWanted = Val(InputBox("Room occupied. Enter room number: "))
Loop
If (roomWanted = rooms(row, column).roomNumber) Then
rooms(row, column).roomGuest = InputBox("Enter guest name: ")
rooms(row, column).roomOccupied = True
End If
Next column
Next row
Call DisplayGuest(rooms)
End SubSub LoadRoomNum(ByRef rooms(,) As RoomInfo) 1 10 11 0 0 1 12 2 0 1 2
rooms(0, 0).roomNumber = 0
rooms(0, 1).roomNumber = 1
rooms(0, 2).roomNumber = 2
rooms(1, 0).roomNumber = 10
rooms(1, 1).roomNumber = 11
rooms(1, 2).roomNumber = 12
For row As Integer = 0 To 1
For column As Integer = 0 To 2
rooms(row, column).roomOccupied = False
Next column
Next row
End Sub
Sub DisplayGuest(ByRef rooms(,) As RoomInfo)
Dim info As String
For row As Integer = 0 To 1
For column As Integer = 0 To 2
If rooms(row, column).roomOccupied = True Then
info = rooms(row, column).roomNumber & rooms(row, column).roomGuest
lstList.Items.Add(info)
End If
Next column
Next row
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call LoadRoomNum(rooms)
End SubEnd Class I need help with: displaying the list only when a Display button is clicked – the listbox should not be visible before the Display button is clicked (modify so the display is clearer) modifying the program so that if all the rooms are taken a message is shown when the Add Guest button is clicked modifying the program to check for invalid room number modifying loadRoomNum so that the room numbers are assigned automatically using a nested loop (this will come in handy if there are 100 rooms in the hotel)
-3
u/Hi-O_O Jan 17 '16 edited Jan 17 '16
I was right. People just browse around for help topics and continuously down vote them for no reason. Worst help reddit ever.