473,405 Members | 2,421 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,405 software developers and data experts.

vbScript eval() function equivalent in VB.Net - Dynamically evaluate code

Hi,

I'd like to be able to evaluate some code dynamically in VB.Net. What
I'd like to achieve especially is this:

dim myForm as Form = new myDLLName.Form1

What I want really is the possibility to do this:

dim x as string = "2"
eval ("dim myForm as Form = new myDLLName.Form"+x)

I was used to be able to do that in vbScript and found it was very
practical and now I would like to be able to do it in VB.Net if
possible.

Any ideas or workaround?

neilsanner

Jan 31 '06 #1
2 8826
<ne********@yahoo.com> schrieb:
dim x as string = "2"
eval ("dim myForm as Form = new myDLLName.Form"+x)

I was used to be able to do that in vbScript and found it was very
practical and now I would like to be able to do it in VB.Net if
possible.

<URL:http://dotnet.mvps.org/dotnet/code/techniques/#ClassByName>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Jan 31 '06 #2
Hey thanks buddy!!! That's awesome!!! I don't speak german but thanks
to google translate I was able to figure it out. Here are my findings:

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Dim currentDomain As AppDomain = AppDomain.CurrentDomain
'Provide the current application domain evidence for the
assembly.
Dim asEvidence As Evidence = currentDomain.Evidence 'If we
don't do this, it won't be able to find the assembly of our custom .dll
library
'Load the assembly from the application directory using a
simple name.
'Create the assembly
currentDomain.Load("CustomDLL", asEvidence)
'Get the form
Dim daForm As Form = DirectCast(CreateObject("CustomDLL",
"CustomDLL.Form1"), System.Windows.Forms.Form)
daForm.ShowDialog()
End Sub
Private Function CreateObject(ByVal AssemblyName As String, ByVal
TypeName As String) As Object
'Make an array for the list of assemblies.
Dim assems As [Assembly]() =
AppDomain.CurrentDomain.GetAssemblies()
'Search for the assembly and return the object specified
For Each asm As System.Reflection.Assembly In assems
Console.WriteLine(asm.FullName)
If asm.FullName.StartsWith(AssemblyName & ",") Then
Return asm.CreateInstance(TypeName)
End If
Next asm
End Function

neilsanner
Herfried K. Wagner [MVP] wrote:
<ne********@yahoo.com> schrieb:
dim x as string = "2"
eval ("dim myForm as Form = new myDLLName.Form"+x)

I was used to be able to do that in vbScript and found it was very
practical and now I would like to be able to do it in VB.Net if
possible.

<URL:http://dotnet.mvps.org/dotnet/code/techniques/#ClassByName>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>


Feb 1 '06 #3

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

Similar topics

12
by: lawrence | last post by:
I have a string which I want to send to eval(). How can I test it ahead of time to make sure it is valid code? I don't want to send it to eval and get parse errors. I want to do something like...
9
by: HikksNotAtHome | last post by:
This is a very simplified example of an Intranet application. But, is there an easier (or more efficient) way of getting the decimal equivalent of a fraction? The actual function gets the select...
4
by: Tony | last post by:
Does anyone know how I can do an "eval" on a string? I have a string back from a database equivalent to "5*6" how can I eval this to an int type of value 30? Taking this further, to evaluate...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
6
by: Dan | last post by:
I need to be able to execute a command that is defined in a string. In VBScript, I can do it with the Eval function. How can I do it in VB.Net? I need something like: Dim x As Integer...
8
by: santel_helvis | last post by:
Hi, Here is my code. function CallDisplay() { nodeobj=new mynode(); x="displayId("+nodeobj+")"; eval(x);
15
by: manstey | last post by:
Hi, I have a text file called a.txt: # comments I read it using this:
7
by: sunrise | last post by:
Dynamic languages like Python and Ruby have eval() function which is very handy when trying to evaluate a mathematical expression. For example: x = 90 puts eval(user_input) imagine that...
13
by: My Pet Programmer | last post by:
The way I usually set up and work with the XMLHttpRequest to execute server side functions and get results is this: var url = "someurl?params=" + params; var conn = createRequest(); // gets an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.