Results 1 to 14 of 14

Thread: Fixing a value to an element of array.

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    Fixing a value to an element of array.

    I hope I got the terminology right.

    I'm creating a simple hotel reservation system.

    The inputbox will validate the users (called a, b, and c) and will loop if the name is wrong. I have no problem at this part.

    Next, if the name matches the array of users I have just stored, they will be allowed to book a room. (room 1, 2 , or 3)

    Here is my problem, how do I attach the room number with particular users so that when the next user use the program (without exiting the program so that memory is not dumped), they will not be allowed to book rooms that have been booked before.


    Here is my simple code.


    VB Code:
    1. guest(0) = "a"
    2. guest(1) = "b"
    3. guest(2) = "c"
    4.  
    5.  
    6. Do
    7.         strinput = InputBox("Who are you?")
    8.         'Check if the name is in the array
    9.     For i = 0 To 2
    10.         If guest(i) = strinput Then
    11.                 blnvalid = True
    12.             ElseIf strinput = "x" Then
    13.             End
    14.             End If
    15.             Next i
    16.     'Loop while a valid name has not been entered
    17.     Loop While Not blnvalid
    18.  
    19. 'PROBLEM STARTS HERE
    20.  
    21. room = InputBox("Choose a room")
    22.  
    23. Do While room < 1 Or room > 3
    24. room = InputBox("Out of range. reenter room 1-3 please")  
    25. Loop                            
    26.  
    27. 'How do I attach particular element of array to
    28. 'the room number so that no element of array (a, b, c)
    29. 'can have the same room number
    Last edited by vert; Jan 30th, 2007 at 12:25 PM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Fixing a value to an element of array.

    How is "room" declared?

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    Re: Fixing a value to an element of array.

    Integer?, I think. There's only fixed possible number of room, being 1 to 3 available spot.

    Should I use variant?

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Fixing a value to an element of array.

    No, an Integer is fine.
    Quote Originally Posted by vert
    VB Code:
    1. 'PROBLEM STARTS HERE
    2.  
    3. room = InputBox("Choose a room")
    4.  
    5. Do While room < 1 Or room > 5
    6. room = InputBox("Out of range")  
    7. Loop                            
    8.  
    9. 'How do I attach particular element of array to
    10. 'the room number so that no element of array (a, b, c)
    11. 'can have the same room number
    However, this tells me that there are not 5 elements in your array and that is why you are getting an out of range error (that is the error that you are getting, correct?). Your array probably goes from 0 to 4.

    This is just a guess as I don't know how you are declaring "room" (only what you are declaring it as.)

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    Re: Fixing a value to an element of array.

    Sorry about the mistake, this is just a mock code of what im doing. (I've edited the code)

    No, I didn't get the error, or any kind of error. That is just deliberate on my part since the program will show that the room number available is only 1-3 and asks for reentry of room number.

    This is what i'm trying to do:

    1) User A, log in, input "a" as name
    2) Book a room, chose room "1"
    3) Both information are displayed. (not in the code)

    THEN

    1) User B comes and put "b" as his name
    2) Try to book room 1, but already booked by user A
    3) Prompt message asking to book another room
    4) This repeats with the next user.

    Basically, I want the program to remember what the room number and user's name that selected that number and deemed that number as unavailable for next user.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Fixing a value to an element of array.

    Is your room array setup like your guest array?
    VB Code:
    1. guest(0) = "a"
    2. guest(1) = "b"
    3. guest(2) = "c"
    4.  
    5. room(0) = "1"
    6. room(1) = "2"
    7. room(2) = "3"

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    Re: Fixing a value to an element of array.

    No... should I?

    What do i do next?

    I don't get it.. how is it possible for my program to store names and matches it with another value to make sure the value does not overlap with other name..

    I'm confused..
    Last edited by vert; Jan 30th, 2007 at 12:41 PM.

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Fixing a value to an element of array.

    The easiest way would be to use recordsets, not arrays. Then you could use a sql statement to find if a room is already booked for the time and/or day in question. If you later expand this to an external database (so the data would remain if you exited the program and ran it again), the additions to link the recordsets to the database is simple.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  9. #9

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    Re: Fixing a value to an element of array.

    Nah, that would be far too complicated for me.. i'm just a newbie and wants the data to be store when the program is still running...

    I know it's possible to store it in database, no idea how to it though, but i think i'm going with simplest solution first...

    Regarding this recordsets that you talk about, what is it and how do I implement it? I've been reading the dummies guide book and it's not very helpful...

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Fixing a value to an element of array.

    Quote Originally Posted by vert
    vert No... should I?
    Well, if you dont store the room number someplace then you have nothing to compare against your guest list.

    Now, if you have a guest array and a room array, now you have two distinct entities that can be compare.

    As database/recordset would be infinately easier to implment. Probably a half and hour and you would be done, including throwing in a few bells and whistles.

    Have a look here.

  11. #11

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    Re: Fixing a value to an element of array.

    So..the database will be much easier for me as a newbie?

    I still want to know how to program in array though if any1 can help me... learning in various ways can hopefully let me see things more clearly in the future...

  12. #12

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    Re: Fixing a value to an element of array.

    I've checked the database guide. unfortunately, I think don't think this is a feasible option, I don't think it should be that complicated. Besides, i doubted my school even has the required MS access!

    I can only do it by array.. can anyone please point me to the right direction? Is it THAT hard to do it without database?

  13. #13

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    32

    Re: Fixing a value to an element of array.

    bumpity bump!

    I need to do this in array. So far, I know that I have to dimmed the rooms as array and somehow have to attach the room number with the particular user..

    Only one user can go on the program at one time... and memory have to be stored inside the program itself. (no database)

    I just need a very very simple array program here, even if it's the most inefficient, sloppy programming, whatever, as long as it works.

    Please? *begs*

  14. #14
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: Fixing a value to an element of array.

    For this simple program, the rooms can be an array of strings, just like the guests array. When a guest chooses a room, make sure the room is empty (If room(i) = "" Then...), then store the guest's name in the room array. When another guest chooses the same room, you will see that the room is occupied if there is another guest's name there already.

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