|
-
Mar 18th, 2007, 10:55 AM
#1
Thread Starter
New Member
Array Question
I have 4 arrays. The program requires 4 users to pick one array.
How do i prevent users to pick one alreay chosen?
Thanks
Last edited by fall_332; Mar 19th, 2007 at 06:19 PM.
-
Mar 18th, 2007, 11:07 AM
#2
Frenzied Member
Re: Array Question
loop through the names of the 4 arrays, when the next user selects an array, check to see if it has already been used, if so, ask them to chose another.
-
Mar 18th, 2007, 11:08 AM
#3
Thread Starter
New Member
Re: Array Question
 Originally Posted by aikidokid
loop through the names of the 4 arrays, when the next user selects an array, check to see if it has already been used, if so, ask them to chose another.
How do I check? Boolean or Counter?
-
Mar 18th, 2007, 11:13 AM
#4
Frenzied Member
Re: Array Question
Tyr something like this:
vb Code:
Dim ArrayName(3) As String
Dim i As Long
For i = 0 To Ubound(ArrayName)
If ArrayName(i) = UsersNextChoice Then 'UsersNextChoice is the selection made by the second, third and fourth users
MsgBox "Please try again, name already taken"
End If
Next
-
Mar 18th, 2007, 11:28 AM
#5
Thread Starter
New Member
Re: Array Question
This is what iv done, please correct:
Code:
Dim number As Integer
Dim number_validated As Boolean
Dim valid_numbers(5) As Integer
Dim num_index As Integer
valid_numbers(1) = "1"
valid_numbers(2) = "2"
valid_numbers(3) = "3"
valid_numbers(4) = "4"
For num_index = 1 To 4
Do
number = InputBox("Please select a number between 1 and 4")
valid_numbers(num_index) = number
number = number_validated
If number_validated = True
Then MsgBox ("That number has already been chosen")
Loop Until number_validated = False
Next
-
Mar 18th, 2007, 02:23 PM
#6
Thread Starter
New Member
Re: Array Question
http://www.rogepost.com/n/8788325591
If you run it on VB you will see it works ok.
My problem is, two users can book the same seat. How can I fix this?
-
Mar 19th, 2007, 08:06 AM
#7
-
Mar 19th, 2007, 11:15 AM
#8
Thread Starter
New Member
Re: Array Question
thanks for that. Do you think it will work in my program?
My program has to loop 5 times without ending.
PS. i fixed the no id problem.
-
Mar 19th, 2007, 11:26 AM
#9
Thread Starter
New Member
Re: Array Question
nvm, i added it in and it jus need a few adjustments.
thanks
-
Mar 19th, 2007, 11:26 AM
#10
Frenzied Member
Re: Array Question
 Originally Posted by fall_332
thanks for that. Do you think it will work in my program?
My program has to loop 5 times without ending.
Give it a go and play with the code a bit. try to adapt it to what your exact requirements are.
The best way to learn is by practising. That's what I do.
I am fairly new to VB myself.
I have only just started feeling confident enough to start answering questions myself
 Originally Posted by fall_332
PS. i fixed the no id problem.
If you still get stuck, let me know.
-
Mar 19th, 2007, 11:29 AM
#11
Thread Starter
New Member
Re: [RESOLVED] Array Question
will do.
thanks
-
Mar 19th, 2007, 02:22 PM
#12
Frenzied Member
Re: [RESOLVED] Array Question
I've had a quick look, but not tested it.
Try the attachment.
Last edited by aikidokid; Apr 23rd, 2007 at 03:10 PM.
-
Mar 19th, 2007, 06:33 PM
#13
Thread Starter
New Member
Re: Array Question
Its something along the line but when user input a seat already chosen, it requires user to input ID again.
The program should not do this :S
Thanks for all help
-
Mar 20th, 2007, 08:39 AM
#14
Frenzied Member
Re: Array Question
In cmdStart, I have commented out the following:
vb Code:
'loop 5 times
'For Counter = 1 To 5
'start program
Call display_results(flight_num, id, name, seat)
'Next
In the Function book_seat, try this:
vb Code:
For X = 0 To UBound(NumUsed)
If MyNum = NumUsed(X) Then
MsgBox "That number has already been chosen, please try again", vbOKOnly + vbInformation, "Number Used"
NotUnique = True
book_seat = 0
Exit Function
Else
Counter1 = Counter1 + 1
If Counter1 = 4 Then
NumUsed(i) = MyNum
i = i + 1
book_seat = MyNum
Exit Function
End If
End If
Next
And lastly, in the display_results, change it to this:
vb Code:
seat = book_seat(seat)
'Add this to check the seat number return, if 0 then user needs to try again.
If seat = 0 Then
seat = book_seat(seat)
End If
Hope this sorts it
-
Mar 20th, 2007, 10:05 AM
#15
Re: Array Question
Use a collection of classes. Reference seats by their ID... move them between available collection and used collection... since seat is a class, you can also assign additional info such as name of occupant.
Or better yet, don't maintain a data struct in memory... save the info into a database so you can use SQL to extract the information (and relationships among/between info) you need.
Last edited by leinad31; Mar 20th, 2007 at 10:10 AM.
-
Mar 20th, 2007, 10:46 AM
#16
Thread Starter
New Member
Re: Array Question
 Originally Posted by aikidokid
In cmdStart, I have commented out the following:
vb Code:
'loop 5 times
'For Counter = 1 To 5
'start program
Call display_results(flight_num, id, name, seat)
'Next
In the Function book_seat, try this:
vb Code:
For X = 0 To UBound(NumUsed)
If MyNum = NumUsed(X) Then
MsgBox "That number has already been chosen, please try again", vbOKOnly + vbInformation, "Number Used"
NotUnique = True
book_seat = 0
Exit Function
Else
Counter1 = Counter1 + 1
If Counter1 = 4 Then
NumUsed(i) = MyNum
i = i + 1
book_seat = MyNum
Exit Function
End If
End If
Next
And lastly, in the display_results, change it to this:
vb Code:
seat = book_seat(seat)
'Add this to check the seat number return, if 0 then user needs to try again.
If seat = 0 Then
seat = book_seat(seat)
End If
Hope this sorts it 
Thank you 
Program should be finished tonight. If I need more help. il ask u again.
Rate = +
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
|