Need Help With two-dimensional array

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2004
Posts: 9
Reputation: scottjo is an unknown quantity at this point 
Solved Threads: 1
scottjo scottjo is offline Offline
Newbie Poster

Need Help With two-dimensional array

 
0
  #1
Aug 30th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 3
Reputation: wjackson has a little shameless behaviour in the past 
Solved Threads: 0
wjackson's Avatar
wjackson wjackson is offline Offline
Newbie Poster

Re: Need Help With two-dimensional array

 
-1
  #2
Aug 25th, 2009
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
  1. Dim reserved As Boolean = False
Then, at the end of your btnReserve Sub, you add
  1. 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.
  1. If HotelArray(intRowNumber, intColumnNumber).reserved = True Then
  2. MessageBox.Show("This room is reserved.", "SORRY!", MessageBoxButtons.OK, MessageBoxIcon.Information)
  3. Exit Sub
  4. End If
...or some variation of that.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 31608 | Replies: 1
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC