Group:  Microsoft Access ยป microsoft.public.access.modulescoding
Thread: Eval() Question

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

Eval() Question
"Lee Wrenn" <noemail[ at ]att.net> 29.09.2006 18:14:57
I am trying to use a function to instantiate an instance of a class and
return the value from the method specified as a parameter of the function.

I have tried a couple of ways and used debug.print to get the values of the
different expressions at execution and have indicated the return values in
comments in the code.

I am using the function as the criteria in a query in the following format:

=getSwitch("Project")

Project is a Get property in the class which looks up the project number in
a table.
When I specify objSwitch.Project in a debug.print statement the proper
project number is returned which says it is being returned from the class
module.

I have indicated the error messages I received after the offending line
where execution stops.
I left one block of commented out alternate code that I tried.

Any help would be appreciated.

Lee Wrenn
________________________________________________________________

Public Function getSwitch(MethodName As String) As Variant
Dim strCmd As String

Dim objSwitch As clsSwitch
Set objSwitch = New clsSwitch

'Debug.Print objSwitch.Project
''Hardcoded line above returns correct project number so get statement in
class is working

'Try Eval on both sides of expression
strCmd = "getSwitch = objSwitch." & MethodName
Debug.Print strCmd
'Returns getSwitch = objSwitch.Project
Eval (strCmd)
'generates error 2482 cant find 'getSwitch'

''Tried Eval on just the right side of expression
' strCmd = "objSwitch." & MethodName
' Debug.Print strCmd
' 'Returns objSwitch.Project
' getSwitch = Eval(strCmd)
' 'generates error 2482 cant find 'objSwitch'

Set objSwitch = Nothing

End Function

_____________________________________________________


Re: Eval() Question
"Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com> 29.09.2006 18:32:33
"Lee Wrenn" <noemail[ at ]att.net> wrote in message
news:OzBDsM$4GHA.3512[ at ]TK2MSFTNGP04.phx.gbl
[Quoted Text]
> I am trying to use a function to instantiate an instance of a class
> and return the value from the method specified as a parameter of the
> function.
>
> I have tried a couple of ways and used debug.print to get the values
> of the different expressions at execution and have indicated the
> return values in comments in the code.
>
> I am using the function as the criteria in a query in the following
> format:
>
> =getSwitch("Project")
>
> Project is a Get property in the class which looks up the project
> number in a table.
> When I specify objSwitch.Project in a debug.print statement the proper
> project number is returned which says it is being returned from the
> class module.
>
> I have indicated the error messages I received after the offending
> line where execution stops.
> I left one block of commented out alternate code that I tried.
>
> Any help would be appreciated.
>
> Lee Wrenn
> ________________________________________________________________
>
> Public Function getSwitch(MethodName As String) As Variant
> Dim strCmd As String
>
> Dim objSwitch As clsSwitch
> Set objSwitch = New clsSwitch
>
> 'Debug.Print objSwitch.Project
> ''Hardcoded line above returns correct project number so get
> statement in class is working
>
> 'Try Eval on both sides of expression
> strCmd = "getSwitch = objSwitch." & MethodName
> Debug.Print strCmd
> 'Returns getSwitch = objSwitch.Project
> Eval (strCmd)
> 'generates error 2482 cant find 'getSwitch'
>
> ''Tried Eval on just the right side of expression
> ' strCmd = "objSwitch." & MethodName
> ' Debug.Print strCmd
> ' 'Returns objSwitch.Project
> ' getSwitch = Eval(strCmd)
> ' 'generates error 2482 cant find 'objSwitch'
>
> Set objSwitch = Nothing
>
> End Function

Since you need to refer to the instance of the class object, I don't
think you can use Eval. However, if you're using Access 2002 or later
(and maybe A2K), you should be able to use CallByName:

getSwitch = CallByName(objSwitch, MethodName, vbMethod)

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Re: Eval() Question
"Tech44" <1744[ at ]tech44.com> 29.09.2006 21:06:05
Thanks Dirk,
Your suggestion worked very well. I did change vbMethod to vbGet
Thanks again.
Lee Wrenn

"Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com> wrote in message
news:e2qIZW$4GHA.3512[ at ]TK2MSFTNGP04.phx.gbl...
[Quoted Text]
> "Lee Wrenn" <noemail[ at ]att.net> wrote in message
> news:OzBDsM$4GHA.3512[ at ]TK2MSFTNGP04.phx.gbl
>> I am trying to use a function to instantiate an instance of a class
>> and return the value from the method specified as a parameter of the
>> function.
>>
>> I have tried a couple of ways and used debug.print to get the values
>> of the different expressions at execution and have indicated the
>> return values in comments in the code.
>>
>> I am using the function as the criteria in a query in the following
>> format:
>>
>> =getSwitch("Project")
>>
>> Project is a Get property in the class which looks up the project
>> number in a table.
>> When I specify objSwitch.Project in a debug.print statement the proper
>> project number is returned which says it is being returned from the
>> class module.
>>
>> I have indicated the error messages I received after the offending
>> line where execution stops.
>> I left one block of commented out alternate code that I tried.
>>
>> Any help would be appreciated.
>>
>> Lee Wrenn
>> ________________________________________________________________
>>
>> Public Function getSwitch(MethodName As String) As Variant
>> Dim strCmd As String
>>
>> Dim objSwitch As clsSwitch
>> Set objSwitch = New clsSwitch
>>
>> 'Debug.Print objSwitch.Project
>> ''Hardcoded line above returns correct project number so get
>> statement in class is working
>>
>> 'Try Eval on both sides of expression
>> strCmd = "getSwitch = objSwitch." & MethodName
>> Debug.Print strCmd
>> 'Returns getSwitch = objSwitch.Project
>> Eval (strCmd)
>> 'generates error 2482 cant find 'getSwitch'
>>
>> ''Tried Eval on just the right side of expression
>> ' strCmd = "objSwitch." & MethodName
>> ' Debug.Print strCmd
>> ' 'Returns objSwitch.Project
>> ' getSwitch = Eval(strCmd)
>> ' 'generates error 2482 cant find 'objSwitch'
>>
>> Set objSwitch = Nothing
>>
>> End Function
>
> Since you need to refer to the instance of the class object, I don't
> think you can use Eval. However, if you're using Access 2002 or later
> (and maybe A2K), you should be able to use CallByName:
>
> getSwitch = CallByName(objSwitch, MethodName, vbMethod)
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>
>


Re: Eval() Question
"Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com> 30.09.2006 06:36:21
"Tech44" <1744[ at ]tech44.com> wrote in message
news:OQSH$tA5GHA.772[ at ]TK2MSFTNGP02.phx.gbl

[Quoted Text]
> Your suggestion worked very well. I did change vbMethod to vbGet
> Thanks again.

You're welcome. Did you find that it didn't work with vbMethod? I
tested with a class module I had lying around, and vbMethod worked for
me.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net