-
I have a sample piece of code to look at a screen control
and report on its properties. For example:
Public Function fcnTest(strForm As String, _
strControl As String) As String
fcnTest = strScreen.strControl.Tag
End function
The problem comes in trying to get VB to replace strScreen and strControl with the form name and control name that is
stored in each variable. So, if one calls the function like
thus:
strSomething = fcnTest("frmMain", "ctlPushButton")
Inside my sample function should look like this, to VB
any how after the compiler get through with it:
Public Function fcnTest(strForm As String, _
strControl As String) As String
fcnTest = frmMain.cltPushButton.Tag
End Function
I am getting compile and run time errors.
Can anyone help me with this truly basic, too basic, query?
Thanks.
-
<?>
strSomething = "fcnTest(""frmMain"", ""ctlPushButton"")"
-
I do not understand or maybe I was not clear enough.
Doesn't this
strSomething = "fcnTest(""frmMain"", ""ctlPushButton"")"
just store what is inbetween double quotes into the variable
strSomething?
What I am trying to do is to come up with a generic function
so that I can pass the form name and the control name
and then manipulate the properties of the control.
Any more suggestions out there?
Thanks.
-
Why don't you pass object variables?
Instead of passing strings, you can pass a Form and a Control object. Even stronger: if you pass a reference to the control, you don't need to pass the form.
eg
Public Function fcnTest(MyControl As Control) As String
fcnTest = MyControl.Tag
End function
You could call the function like this:
strSomething = fcnTest(frmMain.ctlPushButton)
or like this
strSomething = fcnTest(Screen.ActiveControl)