Results 1 to 11 of 11

Thread: Booking system. Avoiding overlap.

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    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:
    1. Dim guest(2) As String
    2. Dim room(2) As String
    3. Dim i As Integer
    4.  
    5. guest(0) = "a"
    6. guest(1) = "b"
    7. guest(2) = "c"
    8.  
    9. 'pretends that there is calculation that
    10. 'validates the user here
    11.  
    12. room(0) = "1"
    13. room(1) = "2"
    14. room(2) = "3"
    15.  
    16. 'Following instruction is what i'm trying to do
    17.  
    18. room = InputBox("enter a room")
    19.  
    20. 'using boolean, if room selected is 1-2
    21. 'a special value (anything) is inserted in that
    22. 'room array so that it cannot be used by the
    23. 'next user
    24.  
    25. 'If rooom is booked, a prompt message is
    26. 'given and process starts again with
    27. 'booking room


    If it's helpful, here is part of the pseudocode:

    VB Code:
    1. boolean isIndexFull(integer index)
    2. if array[index] == marker
    3. return true
    4. else
    5. return false
    6. 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.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Booking system. Avoiding overlap.

    VB Code:
    1. Option Explicit
    2. Private Type AType
    3.     RoomNbr As Integer
    4.     Guest As String
    5.     Reserved As Boolean
    6. End Type
    7. Private Room(2) As AType
    8.  
    9. Private Sub Command1_Click()
    10.  
    11.     Dim intRoom As Integer
    12.    
    13.     intRoom = InputBox("enter a room")
    14.    
    15.     If Room(intRoom).Reserved Then
    16.         MsgBox "already reserved"
    17.     Else
    18.         Room(intRoom).Reserved = True
    19.         Room(intRoom).Guest = InputBox("Please enter your name")
    20.     End If
    21.  
    22. End Sub
    23.  
    24. Private Sub Form_Load()
    25.  
    26.     Dim intIndex As Integer
    27.    
    28.     For intIndex = 0 To UBound(Room)
    29.         Room(intIndex).RoomNbr = intIndex + 1
    30.         Room(intIndex).Reserved = False
    31.     Next
    32.  
    33. End Sub

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    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.

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Booking system. Avoiding overlap.

    I can't do it in "one heading" because in this part

    VB Code:
    1. Private Type AType
    2.     RoomNbr As Integer
    3.     Guest As String
    4.     Reserved As Boolean
    5. End Type
    6. 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.

  5. #5

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    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.

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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

  8. #8

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    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.

  9. #9
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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:
    1. Dim guest(2) As String
    2. Dim room(2) As String
    3. Dim i As Integer
    4.  
    5. guest(0) = "a"
    6. guest(1) = "b"
    7. guest(2) = "c"
    8.  
    9. 'pretends that there is calculation that
    10. 'validates the user here
    11.  
    12. room(0) = "1"
    13. room(1) = "2"
    14. room(2) = "3"
    15.  
    16. 'Following instruction is what i'm trying to do
    17.  
    18. room = InputBox("enter a room")
    to something like
    VB Code:
    1. Option Explicit
    2. Private Type AType
    3.     guest As String
    4.     room As String
    5. End Type
    6.  
    7.  
    8.  
    9. Dim MyRooms(2) As AType
    10. Dim i As Integer
    11.  
    12. MyRooms(0).guest = "a"
    13. MyRooms(1).guest = "b"
    14. MyRooms(2).guest = "c"
    15.  
    16. 'pretends that there is calculation that
    17. 'validates the user here
    18.  
    19. MyRooms(0).room = "1"
    20. MyRooms(1).room = "2"
    21. MyRooms(2).room = "3"
    22.  
    23. 'Following instruction is what i'm trying to do
    24.  
    25. Dim intRoom As Integer
    26. 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:
    1. Private Type AType
    2.     guest As String
    3.     room As String
    4.     occupied As Boolean
    5. End Type
    and in your code

    VB Code:
    1. Dim MyRooms(2) As AType
    2. Dim i As Integer
    3.  
    4. MyRooms(0).guest = "a"
    5. MyRooms(1).guest = "b"
    6. MyRooms(2).guest = "c"
    7.  
    8. 'pretends that there is calculation that
    9. 'validates the user here
    10.  
    11. MyRooms(0).room = "1"
    12. MyRooms(1).room = "2"
    13. MyRooms(2).room = "3"
    14.  
    15. 'Following instruction is what i'm trying to do
    16.  
    17. Dim intRoom As Integer
    18. intRoom = InputBox("enter a room")
    19. MyRooms(intRoom).occupied = True
    You can then find out if a room is occupied with code like

    VB Code:
    1. Dim intIndex As Integer
    2.  
    3. For intIndex = 0 to 2 ' or use UBound
    4.     If MyRooms(intIndex).occupied Then
    5.         MsgBox "occupied"
    6.     Else
    7.         MsgBox "open"
    8.     End If
    9. Next

  10. #10

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    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?

  11. #11
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Booking system. Avoiding overlap.

    VB Code:
    1. Option Explicit
    2. Private Type AType
    3.     guest As String
    4.     room As String
    5.     occupied As Boolean
    6. End Type
    7. Private MyRooms(2) As AType
    8.  
    9. Private Sub Command1_Click()
    10.  
    11. Dim i As Integer
    12.  
    13. MyRooms(0).guest = "a"
    14. MyRooms(1).guest = "b"
    15. MyRooms(2).guest = "c"
    16.  
    17. 'pretends that there is calculation that
    18. 'validates the user here
    19.  
    20. MyRooms(0).room = "1"
    21. MyRooms(1).room = "2"
    22. MyRooms(2).room = "3"
    23.  
    24. 'Following instruction is what i'm trying to do
    25.  
    26. Dim strIB As String
    27. Dim bFound As Boolean
    28. Dim strRoomChoice As String
    29.  
    30. Do Until bFound
    31.     If MyRooms(0).occupied And MyRooms(1).occupied And MyRooms(2).occupied Then
    32.         MsgBox "Sorry, no more room at the inn"
    33.         Exit Sub
    34.     End If
    35.    
    36.     strRoomChoice = InputBox("enter a room")
    37.  
    38.     If (CInt(strRoomChoice)) < 1 Or (CInt(strRoomChoice)) > 2 Then
    39.         MsgBox "Sorry, that's not a vlid room number"
    40.         Exit Sub
    41.     End If
    42.    
    43.     If strRoomChoice = "" Then
    44.         MsgBox "Thanks, see you next time"
    45.         Exit Sub
    46.     Else
    47.         If MyRooms(CInt(strRoomChoice) - 1).occupied Then
    48.             MsgBox "Sorry, room " & strRoomChoice & " is occupied"
    49.         Else
    50.             MsgBox "Okay, room " & strRoomChoice & " is available"
    51.             MyRooms(CInt(strRoomChoice) - 1).occupied = True
    52.             MyRooms(CInt(strRoomChoice) - 1).guest = InputBox("Can I have you name please?")
    53.             bFound = True
    54.         End If
    55.     End If
    56. Loop
    57.    
    58.  
    59.        
    60. 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
  •  



Click Here to Expand Forum to Full Width