在循环的每次迭代中引用不同的控件 [英] Refering to a different control in each iteration of a loop
本文介绍了在循环的每次迭代中引用不同的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的程序中,我有 24 个文本框供用户输入.我想将每个文本框的内容分配给数组的索引.有没有一种方法可以循环执行此操作而不必每次都输入 strItems(0) = MainForm.txtEntry1.text
?这是用 Visual Basic 编写的.
In my program I have 24 text boxes that the user uses for input. I want to assign the contents of each text box to an index of an array. Is there a way I can do this in a loop without having to type out strItems(0) = MainForm.txtEntry1.text
every time? This is written in Visual Basic.
我正在尝试做的一个例子:
An example of what I'm trying to do:
For intCount = 0 to (strItems.length - 1)
strItems(intCount) = txtEntry[intCount + 1]
Next
推荐答案
如果您为所有文本框名称添加前缀(例如 textBoxArray1),则您可以遍历表单上的所有文本框并进行相应处理.喜欢:
If you prefix all of you text boxes names (e.g. textBoxArray1) you can then loop through all the text boxes on the form and process accordingly. Like:
Dim ctrl As Control
For Each ctrl In Me.Controls
If (ctrl.GetType() Is GetType(TextBox)) Then
If(ctrl.Name.StartsWith("textBoxArray") Then
'your code here
End If
End If
Next
这篇关于在循环的每次迭代中引用不同的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文