请问,能否用全局变量名的字符串,返回该变量的值?谢谢!
比如以下代码:public A
Public B
sub XXXX
A=1
B=2
'请问能否编写一个以下功能的函数:
C=转换("A")
D=转换("B")
debug.print C 'C 的结果是 1
debug.print D 'D 的结果是 2
end sub
function 转换(变量名字符串 as String)
???
???
???
end Function
不知能否实现以上功能 谢谢!
Public A As String Public B As String Function convert(str As String) As Integer Select Case str Case Is = "1" convert = 1 Case Is = "2" convert = 2 End Select End Function窗体中
Private Sub Command1_Click() Dim C As Integer Dim D As Integer A = "1" B = "2" C = convert(A) D = convert(B) Debug.Print C Debug.Print D End Sub这会有什么问题
Option Explicit Public str1 As String '看成本窗体的成员,不过外界可以引用 Public str2 As String '看成本窗体的成员,不过外界可以引用 Private Function RefStr(str As String) As String RefStr = CallByName(Me, str, VbGet) End Function Private Sub Command1_Click() str1 = "one string" str2 = "other string" MsgBox RefStr("str1") '通过字符串引用变量 End Sub