Solved

Evaluate String as a sub Routine

Posted on 2011-09-15
1
268 Views
Last Modified: 2012-05-12
I have a string that represents a method I want to execute
on an object inside of a public dictionary object.

Normally the way I'd work with this, is to
do the following:

sub Delete_Asset()
      dFORMS("Assets").delete_
end sub

Open in new window


However, I have SomeFunction,
which gives me the code I need to run
instead:

sub Button_Click()
dim s as string

let s = SomeFunction()
debug.print s
Application.Eval s
end sub

Open in new window


when I run this, debug.print gives:
 dFORMS("Assets").delete_

Open in new window


and then it blows up because it can't evaluate it.
How do I get this to work?
0
Comment
Question by:JustinW
1 Comment
 
LVL 1

Accepted Solution

by:
JustinW earned 0 total points
ID: 36543809
I added a method to the class that allowed me to call the
classes' sub routines by name:

Public Sub Eval_(ParamArray Args() As Variant)
    Select Case Args(0)
        Case "Show_"
            Me.Show_
        Case "Delete_"
            Me.Delete_
        Case "New_"
            Me.New_
        Case "Clear_"
            Me.Clear_
        Case "Save_"
            Me.Save_
        Case Else
            Debug.Print "Selection not Available"

    End Select
End Sub

Open in new window


Now, all I have to do is
dForms("Assets").Eval_("Clear_")

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now