Results 1 to 10 of 10

Thread: Nested loop on mutiple combo box

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2021
    Posts
    18

    Nested loop on mutiple combo box

    Hello , newbie here, I have a project where a user will enter a model number in a textbox and if the model he enter "contain" specific code and compare it with element in a array, well the program will update the a combo box in the menu containing the same code, so the user know that the model number he enter is valid.

    Then thing is , the model number contain multiple code separated in a specific order and update multiple combo box on the menu, my question is can I use multiple nested loop so when the first loop start and the model the user have user is found, it continue looking in the string looking for the next code,with another loop example:

    Let say the user have enter in the textbox this: C-FI-A1-15-PP-ST-ST-RT

    Here is the code to check:



    Code:
    Dim handleOptions() As String = {"PP","AP","WP"}  
    Dim slideArmsOptions() As String = {"TX","TZ","TY"}  
    
    For i As Integer = 0 To handleOptions.length -1  
    	If TXB_CODE_ING.Contains(handleOptions(i)) Then 
    		CMB_HandleOptions  =  handleOptions(i)  
    		For j As Integer = 0  To slideArmsOptions.length -1  
    			If TXB_CODE_ING.Contains(slideArmsOptions(j)) Then  
    				CMB_DrawerSlideArmOptions = slideArmsOptions(j) 
                  
    			End If  
    		Next  
    	End If 
    Next
    So do its the correct way to do it?

    Thank!

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,719

    Re: Nested loop on mutiple combo box

    If you want to check if what has been entered in the TextBox is in an Array then just the the array "contains" property. You seem to be doing it backwards.

    Code:
     If handleOptions.Contains(TXB_CODE_ING.Text) Then
    No need for a Loop.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2021
    Posts
    18

    Re: Nested loop on mutiple combo box

    Yes it look like it , Thank you

  4. #4

    Thread Starter
    Junior Member
    Join Date
    May 2021
    Posts
    18

    Re: Nested loop on mutiple combo box

    I got a message , 'Contains' is not a member of 'System.Array'. ??

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,033

    Re: Nested loop on mutiple combo box

    if Array.IndexOf(handleOptions, TXB_CODE_ING.Text) > -1

  6. #6
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    10,317

    Re: Nested loop on mutiple combo box

    Do you have the System.Linq namespace imported? It should be imported by default unless you're using a version of Visual Studio that is relatively old.
    "Code is like humor. When you have to explain it, itís bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  7. #7

    Thread Starter
    Junior Member
    Join Date
    May 2021
    Posts
    18

    Re: Nested loop on mutiple combo box

    Quote Originally Posted by dday9 View Post
    Do you have the System.Linq namespace imported? It should be imported by default unless you're using a version of Visual Studio that is relatively old.
    It look like it fixed my problem, Thank you!

  8. #8

    Thread Starter
    Junior Member
    Join Date
    May 2021
    Posts
    18

    Re: Nested loop on mutiple combo box

    Quote Originally Posted by .paul. View Post
    if Array.IndexOf(handleOptions, TXB_CODE_ING.Text) > -1
    My problem was fixed by imported System.Linq, but with your method, how I will copy the value to my combo box?

    Thank a lot!

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,033

    Re: Nested loop on mutiple combo box

    Code:
    ComboBox1.SelectedIndex = ComboBox1.FindStringExact(TXB_CODE_ING.Text)

  10. #10

    Thread Starter
    Junior Member
    Join Date
    May 2021
    Posts
    18

    Re: Nested loop on mutiple combo box

    Quote Originally Posted by .paul. View Post
    Code:
    ComboBox1.SelectedIndex = ComboBox1.FindStringExact(TXB_CODE_ING.Text)
    Perfect Thank a lot!

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