Solved

Evaluate String as a sub Routine

Posted on 2011-09-15
1
274 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

630 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