楼主的意思是通过字符串指定属性名来获得属性值吧。Private Sub Command1_Click() MsgBox CallByName(Text1, "Text", VbGet) End Sub
可能是我说得不明白以致楼主还是没看明白。 终极武器,贴代码Private Sub Command1_Click() Dim str As String Dim strArray Dim ctl As Control str = "Text1.Text" strArray = Split(str, ".")
For Each ctl In Controls If ctl.Name = strArray(0) Then str = CallByName(ctl, strArray(1), VbGet) Exit For End If Next MsgBox str End Sub你自己把这个整理成一个函数比如cd() 然后把y=i改成y=cd(i)就可以了。
i=text1.text
y=i
MsgBox CallByName(Text1, "Text", VbGet)
End Sub
终极武器,贴代码Private Sub Command1_Click()
Dim str As String
Dim strArray
Dim ctl As Control
str = "Text1.Text"
strArray = Split(str, ".")
For Each ctl In Controls
If ctl.Name = strArray(0) Then
str = CallByName(ctl, strArray(1), VbGet)
Exit For
End If
Next
MsgBox str
End Sub你自己把这个整理成一个函数比如cd()
然后把y=i改成y=cd(i)就可以了。