|
-
Jan 30th, 2007, 11:00 AM
#1
Thread Starter
Member
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:
guest(0) = "a"
guest(1) = "b"
guest(2) = "c"
Do
strinput = InputBox("Who are you?")
'Check if the name is in the array
For i = 0 To 2
If guest(i) = strinput Then
blnvalid = True
ElseIf strinput = "x" Then
End
End If
Next i
'Loop while a valid name has not been entered
Loop While Not blnvalid
'PROBLEM STARTS HERE
room = InputBox("Choose a room")
Do While room < 1 Or room > 3
room = InputBox("Out of range. reenter room 1-3 please")
Loop
'How do I attach particular element of array to
'the room number so that no element of array (a, b, c)
'can have the same room number
Last edited by vert; Jan 30th, 2007 at 12:25 PM.
-
Jan 30th, 2007, 12:03 PM
#2
Re: Fixing a value to an element of array.
-
Jan 30th, 2007, 12:06 PM
#3
Thread Starter
Member
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?
-
Jan 30th, 2007, 12:13 PM
#4
Re: Fixing a value to an element of array.
No, an Integer is fine.
 Originally Posted by vert
VB Code:
'PROBLEM STARTS HERE
room = InputBox("Choose a room")
Do While room < 1 Or room > 5
room = InputBox("Out of range")
Loop
'How do I attach particular element of array to
'the room number so that no element of array (a, b, c)
'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.)
-
Jan 30th, 2007, 12:21 PM
#5
Thread Starter
Member
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.
-
Jan 30th, 2007, 12:27 PM
#6
Re: Fixing a value to an element of array.
Is your room array setup like your guest array?
VB Code:
guest(0) = "a"
guest(1) = "b"
guest(2) = "c"
room(0) = "1"
room(1) = "2"
room(2) = "3"
-
Jan 30th, 2007, 12:35 PM
#7
Thread Starter
Member
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.
-
Jan 30th, 2007, 01:03 PM
#8
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
-
Jan 30th, 2007, 01:06 PM
#9
Thread Starter
Member
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...
-
Jan 30th, 2007, 01:40 PM
#10
Re: Fixing a value to an element of array.
 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.
-
Jan 30th, 2007, 01:46 PM
#11
Thread Starter
Member
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...
-
Jan 30th, 2007, 02:18 PM
#12
Thread Starter
Member
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?
-
Jan 30th, 2007, 06:31 PM
#13
Thread Starter
Member
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*
-
Jan 30th, 2007, 07:18 PM
#14
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|