473,396 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Execute function

Is there a way to execute a function from a text representation of the
function.

Like,

Dim strFunction as String
strFunction = "Now()"

Is there any function, or process I can call and pass to it strFunction
where when it executes it will return what Now() returns?

Thanks,

Byron...
Nov 21 '05 #1
3 1172

Yes, using Reflection:

Dim objType As Type
Dim d As DateTime
Dim objResult As Object

objType = d.GetType()

objResult = objType.InvokeMember("Now",
Reflection.BindingFlags.GetProperty, Nothing, d, Nothing)

MessageBox.Show(objResult.ToString)

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com
"Byron Hopp" <bh***@matrixcomputer.com> escribió en el mensaje
news:ev**************@TK2MSFTNGP14.phx.gbl...
Is there a way to execute a function from a text representation of the
function.

Like,

Dim strFunction as String
strFunction = "Now()"

Is there any function, or process I can call and pass to it strFunction
where when it executes it will return what Now() returns?

Thanks,

Byron...

Nov 21 '05 #2
Byron,

"Byron Hopp" <bh***@matrixcomputer.com> schrieb:
Is there a way to execute a function from a text representation of the
function.


Calling a method by its name
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=callbyname&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #3

"Carlos J. Quintero [.NET MVP]" <ca*****@NOSPAMsogecable.com> wrote in
message news:e4*************@TK2MSFTNGP15.phx.gbl...

Yes, using Reflection:

Dim objType As Type
Dim d As DateTime
Dim objResult As Object

objType = d.GetType()

objResult = objType.InvokeMember("Now",
Reflection.BindingFlags.GetProperty, Nothing, d, Nothing)

MessageBox.Show(objResult.ToString)

--

Carlos J. Quintero


Hah! I was going to post something very similar to this topic last week!
Fortunately, I waited and found another way to do it as I didn't want to
execute a "string", always frowned upon doing things like that. But, I'm
glad that now I know how to do it for future reference.

Thanks,

Mythran
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: TheDustbustr | last post by:
<code> from __future__ import generators from time import time threads= def sleep(n): print "In Sleep" t=time() while (t+n>time()): yield None
9
by: PyPK | last post by:
Hi if I have a function called tmp=0 def execute(): tmp = tmp+1 return tmp also I have def func1(): execute() ....
4
by: Sergey Suleymanov | last post by:
Documentation says "By default, only the owner (creator) of the function has the right to execute it." But for me newly created function has execute privilege to public by default. And we have...
5
by: Gustavo Randich | last post by:
Hello, I'm writing an automatic SQL parser and translator from Informix to DB2. Now I'm faced with one of the most difficult things to translate, the "foreach execute procedure" functionality...
3
by: Lyle Fairfield | last post by:
MS-SQL Server utilities Enterprise Manager and Query Analyzer will model almost any MS-SQL object as a simple script file with a default ".sql" extension. But how to "run these files? They are...
0
by: Dexter | last post by:
Hello all, I have the following problem. I need to execute a javascript function of inside of a asp.net page. .... Private Sub execute_test() '... here a asp.net code '... here a asp.net code...
7
by: msxkim | last post by:
How to execute functions in the parent class first and then functions in the child class? For example, I have a parent class with functions 'ONE' and 'TWO' and child class has a function 'THREE'. ...
2
by: Sike | last post by:
Hi everyone, I've been browsing this and a few other related newsgroups trying to get my head around this problem, and so far all the trails seem to go cold, without an acceptable solution being...
9
by: Pachydermitis | last post by:
Hi, Is there any way to execute a function by using it's pointer? The reason I want to do this is: I have a control on a form that I have wrapped with a class. I want to be able to dynamically...
17
by: =?Utf-8?B?SmltIFJvZGdlcnM=?= | last post by:
I am trying to replace a huge chunck of code that currently I incorporate with an #Include directive. The program rarely has to flow through that code, so I thought it would be better if I used...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.