vb for循环变量与字符串组合

2025-05-09 01:50:43
推荐回答(2个)
回答1:

你必须使用空间数组,否则无法使用循环

二楼说的方法我前面已经try过了,也不行啊,主要是VBA不支持DIm txt as TextBox这样的语句的
我的代码是

VBA不支持的东西太多了
Private Sub CommandButton1_Click()
Dim txt As TextBox, lab As Label
For i = 1 To 2
For Each txt In Me
If txt.ControlTipText = "Text" & i Then
For Each lab In Me
If lab.ControlTipText = "Label" & i Then lab.Caption = txt.Text
Next
End If
Next
Next
End Sub
Private Sub UserForm_Initialize()
'On Error Resume Next
'Dim con As Control
'For Each con In Me
'con.ControlTipText = con.Name
'Next
End Sub
这个定义就不支持了

回答2:

这个你是肯定要用到控件数组的哈,但是如果你用的是VB.net的话,对不起你是不能够用控件数组的,但是我们可以遍历我们的控件,然后找到他是不是TextBox啥,然后就是循环的了哈,没有什么难度的哈