Results 1 to 16 of 16

Thread: Array Question

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    9

    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.

  2. #2
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    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.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    9

    Re: Array Question

    Quote 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?

  4. #4
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Array Question

    Tyr something like this:

    vb Code:
    1. Dim ArrayName(3) As String
    2. Dim i As Long
    3.  
    4. For i = 0 To Ubound(ArrayName)
    5.     If ArrayName(i) = UsersNextChoice Then    'UsersNextChoice is the selection made by the second, third and fourth users
    6.         MsgBox "Please try again, name already taken"
    7.     End If
    8. Next
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    9

    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

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    9

    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?

  7. #7
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Array Question

    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.
    Last edited by aikidokid; Apr 23rd, 2007 at 03:10 PM.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  8. #8

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    9

    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.

  9. #9

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    9

    Re: Array Question

    nvm, i added it in and it jus need a few adjustments.
    thanks

  10. #10
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Array Question

    Quote 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



    Quote Originally Posted by fall_332
    PS. i fixed the no id problem.


    If you still get stuck, let me know.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  11. #11

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    9

    Re: [RESOLVED] Array Question

    will do.
    thanks

  12. #12
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    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.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  13. #13

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    9

    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

  14. #14
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Array Question

    In cmdStart, I have commented out the following:
    vb Code:
    1. 'loop 5 times
    2. 'For Counter = 1 To 5
    3.  
    4. 'start program
    5. Call display_results(flight_num, id, name, seat)
    6. 'Next


    In the Function book_seat, try this:

    vb Code:
    1. For X = 0 To UBound(NumUsed)
    2.     If MyNum = NumUsed(X) Then
    3.         MsgBox "That number has already been chosen, please try again", vbOKOnly + vbInformation, "Number Used"
    4.         NotUnique = True
    5.         book_seat = 0
    6.         Exit Function
    7.      Else
    8.      Counter1 = Counter1 + 1
    9.         If Counter1 = 4 Then
    10.             NumUsed(i) = MyNum
    11.             i = i + 1
    12.             book_seat = MyNum
    13.             Exit Function
    14.         End If
    15.     End If    
    16. Next

    And lastly, in the display_results, change it to this:
    vb Code:
    1. seat = book_seat(seat)
    2. 'Add this to check the seat number return, if 0 then user needs to try again.
    3. If seat = 0 Then    
    4.     seat = book_seat(seat)
    5. End If

    Hope this sorts it
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  15. #15
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    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.

  16. #16

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    9

    Re: Array Question

    Quote Originally Posted by aikidokid
    In cmdStart, I have commented out the following:
    vb Code:
    1. 'loop 5 times
    2. 'For Counter = 1 To 5
    3.  
    4. 'start program
    5. Call display_results(flight_num, id, name, seat)
    6. 'Next


    In the Function book_seat, try this:

    vb Code:
    1. For X = 0 To UBound(NumUsed)
    2.     If MyNum = NumUsed(X) Then
    3.         MsgBox "That number has already been chosen, please try again", vbOKOnly + vbInformation, "Number Used"
    4.         NotUnique = True
    5.         book_seat = 0
    6.         Exit Function
    7.      Else
    8.      Counter1 = Counter1 + 1
    9.         If Counter1 = 4 Then
    10.             NumUsed(i) = MyNum
    11.             i = i + 1
    12.             book_seat = MyNum
    13.             Exit Function
    14.         End If
    15.     End If    
    16. Next

    And lastly, in the display_results, change it to this:
    vb Code:
    1. seat = book_seat(seat)
    2. 'Add this to check the seat number return, if 0 then user needs to try again.
    3. If seat = 0 Then    
    4.     seat = book_seat(seat)
    5. 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
  •  



Click Here to Expand Forum to Full Width