Results 1 to 8 of 8

Thread: [RESOLVED] Need help with a loop

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Resolved [RESOLVED] Need help with a loop

    Hello everyone on vbforums
    I have a array of 10 coboboxes and 10 textboxes.
    I am doing something like this:

    Code:
    If Index = 1  then text1(1).text = combo1(1).text
    But I wonder if I can do that in a loop

    Code:
    Dim i As Integer
    For i = 1 To 10
    Text1(i).Text = Combo1(i).Text
    Next i

  2. #2
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: Need help with a loop

    You can (and should)! Indexes usually start at 0 though, so you might want to try For i = 0 to 9.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: Need help with a loop

    Code:
    You can (and should)! Indexes usually start at 0 though, so you might want to try For i = 0 to 9.
    But even the index starts at 0, it does not work as expected

  4. #4
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: Need help with a loop

    Post a project or full code sample that demonstrates your problem. Also what do you expect to happen vs. what is happening?

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: Need help with a loop

    If I click combo1(0) to populate text1(0), all text1 array are populated in the same time

  6. #6
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: Need help with a loop

    Yes, your loop will set all text boxes to the content of the combo boxes with the same index. It's essentially doing this:

    Code:
    Text1(1).Text = Combo1(1).Text
    Text1(2).Text = Combo1(2).Text
    Text1(3).Text = Combo1(3).Text
    Text1(4).Text = Combo1(4).Text
    Text1(5).Text = Combo1(5).Text
    Text1(6).Text = Combo1(6).Text
    Text1(7).Text = Combo1(7).Text
    Text1(8).Text = Combo1(8).Text
    Text1(9).Text = Combo1(9).Text
    Text1(10).Text = Combo1(10).Text
    If you just want to set the text of the textbox with the same index as the clicked combobox, just set that single textbox by the passed index:

    Code:
    Text1(Index).Text = Combo1(Index).Text

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: [RESOLVED] Need help with a loop

    thank you Mister
    it is working now

  8. #8
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,852

    Re: [RESOLVED] Need help with a loop

    Code:
    
        Dim cbo As ComboBox
        For Each cbo In Combo1
            Text1(cbo.Index).Text = cbo.Text
        Next
    
    
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

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