For Each

Smee

Well-Known Member
Licensed User
Longtime User
i have a collection of text boxes. How do i use a for each to adjust the property(s) of them all. in fact for any control sorry i mean view. is there already a thread on this? i could not find any when searching
 

Smee

Well-Known Member
Licensed User
Longtime User
Sorry Erel,

I should have said i have several edit text boxes. i want to set properties etc in a for each group.


in vb similar was
B4X:
For each control in form
if control=textbox then
end if
next

I would also be checking that each text box has been filled in.
 
Last edited:
Upvote 0

grant1842

Active Member
Licensed User
Longtime User
Are you storing the editboxes in an array?
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
hi Grant,

No. if i do that i would not really need to use For Each. The structure of a traditional For Each is that each control/view can be addressed based on its type not its name.

Thanks for the reply
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You can do:

B4X:
For i = 0 To Activity.NumberOfViews-1
   If Activity.GetView(i) Is EditText Then
      Dim ET As EditText = Activity.GetView(i)
      Log(i&" "&ET.Text)
       'And anything else
   End If
Next

If the EditTexts are on a Panel, change Activity for PanelName.
 
Upvote 0

grant1842

Active Member
Licensed User
Longtime User
All a for each loop does is iterate through a list/array of objects, returning an object of your type cast for each object. With that being said, you need a list/array to iterate through.

For me, if you're not wanting to use an array or list, then you could put the edits on a panel and loop through them that way.

EDIT: Looks like steve beat me to the punch :p
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
Steve\Grant

Thanks guys, thats exactly what i need.

Cheers
 
Upvote 0
Top