|
-
Jan 31st, 2007, 12:11 PM
#1
Thread Starter
Member
Booking system. Avoiding overlap.
I've asked this before but I've decided to make a new one since it gets far too complicated and I want it simple.
This program has to be done with array, no database.
Example:
1)User A validates himself
2)Book a room
3)an array in that room number is filled with a value, rendered it as unavailable
1)User B comes, validates himself
2)Book a room
3)Try to book same room as user A, but that particular array have been altered, making it unavailable
4) Prompt message is given and it loops to the first booking question
VB Code:
Dim guest(2) As String
Dim room(2) As String
Dim i As Integer
guest(0) = "a"
guest(1) = "b"
guest(2) = "c"
'pretends that there is calculation that
'validates the user here
room(0) = "1"
room(1) = "2"
room(2) = "3"
'Following instruction is what i'm trying to do
room = InputBox("enter a room")
'using boolean, if room selected is 1-2
'a special value (anything) is inserted in that
'room array so that it cannot be used by the
'next user
'If rooom is booked, a prompt message is
'given and process starts again with
'booking room
If it's helpful, here is part of the pseudocode:
VB Code:
boolean isIndexFull(integer index)
if array[index] == marker
return true
else
return false
end if
Please note that this is a mock part of my program and I have spent considerable time figuring this out. Being a newbie, I am totally clueless in how array works and have spent more than 3 hours on this part of code alone with no avail. I'm not trying to get the easy way out.
-
Jan 31st, 2007, 12:29 PM
#2
Re: Booking system. Avoiding overlap.
VB Code:
Option Explicit
Private Type AType
RoomNbr As Integer
Guest As String
Reserved As Boolean
End Type
Private Room(2) As AType
Private Sub Command1_Click()
Dim intRoom As Integer
intRoom = InputBox("enter a room")
If Room(intRoom).Reserved Then
MsgBox "already reserved"
Else
Room(intRoom).Reserved = True
Room(intRoom).Guest = InputBox("Please enter your name")
End If
End Sub
Private Sub Form_Load()
Dim intIndex As Integer
For intIndex = 0 To UBound(Room)
Room(intIndex).RoomNbr = intIndex + 1
Room(intIndex).Reserved = False
Next
End Sub
-
Jan 31st, 2007, 12:43 PM
#3
Thread Starter
Member
Re: Booking system. Avoiding overlap.
I'm sorry if i'm asking too much but can you show me the code in just one heading?...
under the "private sub cmd click"?
Also, I notice that the program just prompted the user when they inputted a booked room but does not loop to the start?
I dont need the name's validation at this stage because unvalidated users cannot get at the booking stage if they are not valid..
Also, what is Ubound? And i've never come across "Room(intIndex).RoomNbr" with the use of period after the array...what is it for?
I'm sorry if I sound like an idiot in VB, but I am. Can you show it again in a simplest way possible, even if it's the most inefficient sloppy programming because I want to learn from the very start.
-
Jan 31st, 2007, 12:55 PM
#4
Re: Booking system. Avoiding overlap.
I can't do it in "one heading" because in this part
VB Code:
Private Type AType
RoomNbr As Integer
Guest As String
Reserved As Boolean
End Type
Private Room(2) As AType
I'm defining my own datatype and that has to be dome at the global level. A datatype is like Integer or String, etc except mine has three parts so that the data can be kept together in an array (Room) that I made from that type. What I did would be like
Dim var(2) As Integer
only more robust.
The use of the period comes into play because of the three parts. If you use my code and type Room with a period after it you'll see that Intellisense knows about the three parts.
-
Jan 31st, 2007, 01:02 PM
#5
Re: Booking system. Avoiding overlap.
Oh, and UBound is the upper boundry of an array, so since the first entry in an array is (0) the UBound of an array with 3 entries is 2.
-
Jan 31st, 2007, 01:10 PM
#6
Thread Starter
Member
Re: Booking system. Avoiding overlap.
Thanks for your help martin, but i'm afraid I can't do it this way...
I just want to change the seat booking part of my program and since the seat codes is already in a function, with parameter passing and everything, doing it with three seperate subprograms will be far too complicated for me to implement...
Besides, I don't understand half of what the code is doing..i can't code something i don't understand..
Thanks again martin..
Anyone else know a simpler way of doing this? I just need a very very simple one, as long as it works, i don't care how sloppy it is.
-
Jan 31st, 2007, 01:18 PM
#7
Re: Booking system. Avoiding overlap.
Did you get the "three seperate subprograms" idea from what I posted. If you did I'm sorry if I mislead you. In any case if you'll zip up your project and attach it I take a look at it when I'm done playing poker
-
Jan 31st, 2007, 01:39 PM
#8
Thread Starter
Member
Re: Booking system. Avoiding overlap.
sendspace link
The end program will look similar to this, but i dont have the final program with me just now.
Everything is ok with exception of booking the room, that is why i'm kind of afraid of changing things because it took me quite a long time to even comprehend basic programming.
N.B I only want the program to know when other rooms are booked when it is still running. A bit unrealistic real life situation, but I want it to be like this.
Thanks.
-
Jan 31st, 2007, 02:46 PM
#9
Re: Booking system. Avoiding overlap.
You don't have to change much to adapt your code to my method. You just need to change this
VB Code:
Dim guest(2) As String
Dim room(2) As String
Dim i As Integer
guest(0) = "a"
guest(1) = "b"
guest(2) = "c"
'pretends that there is calculation that
'validates the user here
room(0) = "1"
room(1) = "2"
room(2) = "3"
'Following instruction is what i'm trying to do
room = InputBox("enter a room")
to something like
VB Code:
Option Explicit
Private Type AType
guest As String
room As String
End Type
Dim MyRooms(2) As AType
Dim i As Integer
MyRooms(0).guest = "a"
MyRooms(1).guest = "b"
MyRooms(2).guest = "c"
'pretends that there is calculation that
'validates the user here
MyRooms(0).room = "1"
MyRooms(1).room = "2"
MyRooms(2).room = "3"
'Following instruction is what i'm trying to do
Dim intRoom As Integer
intRoom = InputBox("enter a room")
Do you see how similar that is? You may notice however that it doesn't solve your problem of knowing if a room is booked. To do that all you need to do is to modify AType like so
VB Code:
Private Type AType
guest As String
room As String
occupied As Boolean
End Type
and in your code
VB Code:
Dim MyRooms(2) As AType
Dim i As Integer
MyRooms(0).guest = "a"
MyRooms(1).guest = "b"
MyRooms(2).guest = "c"
'pretends that there is calculation that
'validates the user here
MyRooms(0).room = "1"
MyRooms(1).room = "2"
MyRooms(2).room = "3"
'Following instruction is what i'm trying to do
Dim intRoom As Integer
intRoom = InputBox("enter a room")
MyRooms(intRoom).occupied = True
You can then find out if a room is occupied with code like
VB Code:
Dim intIndex As Integer
For intIndex = 0 to 2 ' or use UBound
If MyRooms(intIndex).occupied Then
MsgBox "occupied"
Else
MsgBox "open"
End If
Next
-
Jan 31st, 2007, 03:08 PM
#10
Thread Starter
Member
Re: Booking system. Avoiding overlap.
Thanks. I'll give it a try. Btw, for the very bottom code, I don't think it to say open if it's available....
How do I loop back to the intRoom = InputBox("enter a room") if it is occupied?
-
Jan 31st, 2007, 06:05 PM
#11
Re: Booking system. Avoiding overlap.
VB Code:
Option Explicit
Private Type AType
guest As String
room As String
occupied As Boolean
End Type
Private MyRooms(2) As AType
Private Sub Command1_Click()
Dim i As Integer
MyRooms(0).guest = "a"
MyRooms(1).guest = "b"
MyRooms(2).guest = "c"
'pretends that there is calculation that
'validates the user here
MyRooms(0).room = "1"
MyRooms(1).room = "2"
MyRooms(2).room = "3"
'Following instruction is what i'm trying to do
Dim strIB As String
Dim bFound As Boolean
Dim strRoomChoice As String
Do Until bFound
If MyRooms(0).occupied And MyRooms(1).occupied And MyRooms(2).occupied Then
MsgBox "Sorry, no more room at the inn"
Exit Sub
End If
strRoomChoice = InputBox("enter a room")
If (CInt(strRoomChoice)) < 1 Or (CInt(strRoomChoice)) > 2 Then
MsgBox "Sorry, that's not a vlid room number"
Exit Sub
End If
If strRoomChoice = "" Then
MsgBox "Thanks, see you next time"
Exit Sub
Else
If MyRooms(CInt(strRoomChoice) - 1).occupied Then
MsgBox "Sorry, room " & strRoomChoice & " is occupied"
Else
MsgBox "Okay, room " & strRoomChoice & " is available"
MyRooms(CInt(strRoomChoice) - 1).occupied = True
MyRooms(CInt(strRoomChoice) - 1).guest = InputBox("Can I have you name please?")
bFound = True
End If
End If
Loop
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|