-
Jan 22nd, 2021, 01:38 PM
#1
Thread Starter
Fanatic Member
[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
-
Jan 22nd, 2021, 01:52 PM
#2
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.
-
Jan 22nd, 2021, 01:59 PM
#3
Thread Starter
Fanatic Member
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
-
Jan 22nd, 2021, 02:01 PM
#4
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?
-
Jan 22nd, 2021, 02:02 PM
#5
Thread Starter
Fanatic Member
Re: Need help with a loop
If I click combo1(0) to populate text1(0), all text1 array are populated in the same time
-
Jan 22nd, 2021, 02:07 PM
#6
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
-
Jan 22nd, 2021, 02:11 PM
#7
Thread Starter
Fanatic Member
Re: [RESOLVED] Need help with a loop
thank you Mister
it is working now
-
Jan 22nd, 2021, 09:57 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|