to foolishtiger 这种方法不能解决问题,我得str1只能是string,是从其他字符串得到的,而callbyname调用的对象名是str1
Dim objTest as Object Select Case str1 Case "Text1" Set objTest=Text1 Case "Text2" Set objTest=Text2 Case Else Set objTest=Nothing End Select然后引用objTest进行操作.
参考这个 Private Sub Command1_Click() Dim objTest As Object Dim strT1 As String Dim strT2 As String strT1 = Text1.Text strT2 = Time For Each objTest In Form1 If objTest.Name = strT1 Then w ByVal objTest, strT2 Exit For End If Next End Sub Private Function w(ByVal l As Object, l2 As String) l.Caption = l2 End Function
这种方法不能解决问题,我得str1只能是string,是从其他字符串得到的,而callbyname调用的对象名是str1
Select Case str1
Case "Text1"
Set objTest=Text1
Case "Text2"
Set objTest=Text2
Case Else
Set objTest=Nothing
End Select然后引用objTest进行操作.
Private Sub Command1_Click()
Dim objTest As Object
Dim strT1 As String
Dim strT2 As String
strT1 = Text1.Text
strT2 = Time
For Each objTest In Form1
If objTest.Name = strT1 Then
w ByVal objTest, strT2
Exit For
End If
Next
End Sub
Private Function w(ByVal l As Object, l2 As String)
l.Caption = l2
End Function
case语句有多少分支是不知道的,所以这样也不能解决问题
不过最好把对象的名称,写到数据库里。
于明刚能说得详细点吗?老妖的程序一时没有看懂
举个例子:比如说你有一个FORM,FORM里有一个控件名称是A,A有一个属性是TEXT,现在你要通过数据库里的记录和通用的程序给这个控件赋值。那么,首先从数据库里按一定条件取出一条记录,得知控件的名称和属性,那么可以在此FORM里用FOR EACH,来循环所有控件,用FORM里的每个控件的名称和数据库里取出的控件名称进行比较。如果相同那么使用CALLBYNAME,通过数据库里取出的控件名称和属性/方法,进行取值/赋值/调用方法的操作。我个人体会是进行方法的调用是比较实际而可用的,进行通用增删改也是一种比较好的方法。