I have 8 textfield on my window, I named them as txt_msg_1, txt_msg_2,…, txt_msg_8. If I read a text file line by line, and want to put txt_msg_1 with line1, txt_msg_2 with line2…
How can I do with a for loop, such as
for i as integer = 1 to 8
txt_msg_(i). text = line(i)
next
I know in VB.NET I can use Ctype to get controls by name, does XOJO did the similar way or has another method? Thanks!
I don’t know about a Ctype function, but maybe someone else might know about a similar function. I think it is recommended that you use a Control Set with each of the txt_msg textfields having an index 0-7 (arrays are 0 based). Then in your loop you can do exactly what you have above, except loop from 0 to 7. If that loop is going to be nested in any other for…next loops, then make sure your end of the loop is next i, instead of just next.
dim i as integer
dim ctrl as control
For i=0 To Me.ControlCount-1
ctrl=Me.control(i)
If ctrl IsA TextFieldl and ctrl.Name="mycontrol" and ctrl.index=myIndex then
do whatever
exit for
end if
next i
dim i as integer
dim ctrl as control
For i=0 To Me.ControlCount-1
ctrl=Me.control(i)
If ctrl IsA TextFieldl and ctrl.Name="mycontrol" and ctrl.index=myIndex then
do whatever
exit for
end if
next i
ME is current window[/quote]
Thanks! But just curious, do I have to search all the controls within the window every time when I want to get a certain control?
It’s simple to write a
Ctype(Me.Controls("Txt_msg_" + i.tostring), textbox). text = line(i)
than to have a for loop.
But if there is no other way to do it, it’s better than nothing. =)