I have 4 arrays. The program requires 4 users to pick one array.
How do i prevent users to pick one alreay chosen?
Thanks
Printable View
I have 4 arrays. The program requires 4 users to pick one array.
How do i prevent users to pick one alreay chosen?
Thanks
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?Quote:
Originally Posted by aikidokid
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
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
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?
Firstly, have you noticed that if the user inputs something that you program doesn't accept, there is a continual loop and the app cannot be stopped! :(
Try the attachment and let me know how you get on with it.
Hope it helps. :wave:
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.
nvm, i added it in and it jus need a few adjustments.
thanks
Give it a go and play with the code a bit. try to adapt it to what your exact requirements are.Quote:
Originally Posted by fall_332
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 :bigyello:
:thumb:Quote:
Originally Posted by fall_332
If you still get stuck, let me know. :)
will do.
thanks http://www.vbforums.com/images/smilies/thumb.gif
I've had a quick look, but not tested it.
Try the attachment. :thumb:
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
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 :thumb:
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.
Quote:
Originally Posted by aikidokid
Thank you :)
Program should be finished tonight. If I need more help. il ask u again.
Rate = +