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
Solved

Evaluate String as a sub Routine

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

860 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