I need help with a program. It’s suppose to keep track of motel reservations.

A guest’s name is entered and then assigned to a room. The motel has three floors and 40 rooms (numbered 1 to 40).

The program is suppose to reserve a room, cancel a reservation, and display all the rooms on one floor along with the names of guests who have reserved the rooms. Guest cannot reserve a room that has already been reserved.

One form will be used to display the reservations for one floor, and a separate form will be used for making/canceling reservations. When canceling a reservation, provide some sort of "are you sure" safety check, such as a message box. At least one two-dimensional array is to be used..

The problem I am having is that I’m not sure how to stop the user from reserving a room that has already been reserved.. The program just displays the information entered in. The code is located below. Any help would be apprecaiated.

Public Class Form1
Inherits System.Windows.Forms.Form
Dim HotelArray(3, 40)
Dim intRowNumber As Integer
Dim intColumnNumber As Integer
Dim x As Integer
Dim y As Integer
Dim mblnFloorFound As Boolean = False
Dim mblnRoomFound As Boolean = False
Dim mintRoomSub As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For x = 1 To 3
lstFloor.Items.Add(x)
Next x
End Sub

Private Sub btnReserve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReserve.Click
intFloor = CInt(lstFloor.SelectedIndex) + 1
intRoom = CInt(NumericUpDown1.Value)
strName = CStr(txtName.Text)
intRowNumber = intFloor
intColumnNumber = intRoom
HotelArray(intRowNumber, intColumnNumber) = intFloor & " " & intRoom
End Sub

Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
lstGuestInfo.Items.Add("Floor Number:" & " " & HotelArray(intRowNumber, intColumnNumber) & " " & "Customer Name:" & " " & strName)
End Sub

End Class

I am not sure if this is all of your code, but you are missing a flag that tells whether a room is reserved or not. Start by declaring

Dim reserved As Boolean = False

Then, at the end of your btnReserve Sub, you add

HotelArray(intRowNumber, intColumnNumber).reserved = True

Also, before you declare a room as "reserved", you will have to check to make sure that it is not already reserved.

If HotelArray(intRowNumber, intColumnNumber).reserved = True Then
MessageBox.Show("This room is reserved.", "SORRY!", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If

...or some variation of that.

commented: 5 years late, you think they still care? -7

Hello everyone. i am trying to display a two dimensional array in a multi-line textbox and always gets this error: NUMBER OF INDICES IS LESS THAN THE NUMBER OF DIMENSIONS OF THE INDEXED ARRAY. Below is my code. I am really just starting to learn vb.net programming. so i am really lost.. thank you.

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim planet(,) As String = New String(1, 2) {{"venus", "pluto", "earth"}, {"blue", "gray", "green"}}
        Dim p As Integer

        While p < 3
            TextBox1.Text = TextBox1.Text & " " & planet(p)
            p = p + 1
        End While
    End Sub
End Class

What is the value of your variable p?
If the length of your array can hold 4 value, then the indexes of those value in your array will 0,1,2,3.

Note: Please be reminded that array index always start at 0.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.