Solved

Evaluate String as a sub Routine

Posted on 2011-09-15
1
266 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article will show you how to use shortcut menus in the Access run-time environment.
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

759 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

18 Experts available now in Live!

Get 1:1 Help Now