473,385 Members | 1,798 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,385 software developers and data experts.

Simple Eval() (Ithink) question



I'm new to Visual Web 2005 using VB:

....trying to get something like the below to run.
Apparently, I need something other than the eval function, but what?

Thanks in advance

Jeff
Dim x As String
x = "5 4"

If Eval(x) Then
Label1.Text = "It Worked"
End If

--
Posted via a free Usenet account from http://www.teranews.com

Sep 13 '06 #1
8 2152
Sept. 13, 2006

I don't know about your code sample as I've never really seen the Eval
method used.

What most people do in that situation, is something like this:

If 5 4 then
label1.text = "It worked"
end if

or if you needed to make sure the first integer passed in by the user was
greater than a number you have in mind... then you could do something like
this: (where textbox1.text contains the user's number)

if textbox1.text [yournumber] then
.....

Basically, the "if" statement automatically evaluates simple operations such
as or < or =True... or "if [passedinboolean]=False AND Textbox1.text 3
then" ... stuff like that.

Hope this helps!
--

Joseph Bittman
Microsoft Certified Solution Developer
Microsoft Most Valuable Professional -- DPM

Blog/Web Site: http://CactiDevelopers.ResDev.Net/
"Jeff" <no**@none.comwrote in message
news:45***********************@free.teranews.com.. .
>

I'm new to Visual Web 2005 using VB:

...trying to get something like the below to run.
Apparently, I need something other than the eval function, but what?

Thanks in advance

Jeff
Dim x As String
x = "5 4"

If Eval(x) Then
Label1.Text = "It Worked"
End If

--
Posted via a free Usenet account from http://www.teranews.com
Sep 13 '06 #2

Jeff wrote:
I'm new to Visual Web 2005 using VB:

...trying to get something like the below to run.
Apparently, I need something other than the eval function, but what?

Thanks in advance

Jeff
Dim x As String
x = "5 4"

If Eval(x) Then
Label1.Text = "It Worked"
End If

1. Create a class in JScript -

// JScript Source Code
class EvalClass
{
function Evaluate(expression)
{
return eval(expression);
}
}

2. Compile it to a dll (evaluator.dll):

jsc /target:library evaluator.js

3. Reference the dll in your VB.NET project.

4. Write Code:

Dim ec As New EvalClass()
Dim expr As String = "(10 + 6) / 8"
Dim res As Double = CType(ec.Evaluate(expr), Double)

Console.WriteLine("{0} = {1}", expr, res)

The issues... Well, you can actually exectue arbitray bits of JScript
code through this so it might be wise to do a little input validation
(ex: use regex to make sure that the input is a valid mathmatical
expression) and error traping, since the eval function just returns
object - but it actually works pretty well :)

--
Tom Shelton

Sep 13 '06 #3
"Jeff" <no**@none.comschrieb:
I'm new to Visual Web 2005 using VB:

...trying to get something like the below to run.
Apparently, I need something other than the eval function, but what?

Dim x As String
x = "5 4"

If Eval(x) Then
Label1.Text = "It Worked"
End If
Hand-made:

MathLib
<URL:http://www.palmbytes.de/content/dotnet/mathlib.htm>

Dynamic compilation:

Build a Custom .NET "EVAL" Provider
<URL:http://www.eggheadcafe.com/articles/20030908.asp>

Runtime Compilation (A .NET eval statement)
<URL:http://www.codeproject.com/dotnet/evaluator.asp>

Evaluation of numeric expressions using J#:

<URL:http://groups.google.de/group/microsoft.public.dotnet.languages.csharp/msg/9e95759b54a323a7>

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

Sep 13 '06 #4

Tom Shelton wrote:
Jeff wrote:
I'm new to Visual Web 2005 using VB:

...trying to get something like the below to run.
Apparently, I need something other than the eval function, but what?

Thanks in advance

Jeff
Dim x As String
x = "5 4"

If Eval(x) Then
Label1.Text = "It Worked"
End If


1. Create a class in JScript -

// JScript Source Code
class EvalClass
{
function Evaluate(expression)
{
return eval(expression);
}
}

2. Compile it to a dll (evaluator.dll):

jsc /target:library evaluator.js

3. Reference the dll in your VB.NET project.

4. Write Code:

Dim ec As New EvalClass()
Dim expr As String = "(10 + 6) / 8"
Dim res As Double = CType(ec.Evaluate(expr), Double)

Console.WriteLine("{0} = {1}", expr, res)

The issues... Well, you can actually exectue arbitray bits of JScript
code through this so it might be wise to do a little input validation
(ex: use regex to make sure that the input is a valid mathmatical
expression) and error traping, since the eval function just returns
object - but it actually works pretty well :)
I also forgot to mention - you need to reference the
microsoft.jscript.dll in your vb.net project :)

--
Tom Shelton
>
--
Tom Shelton
Sep 13 '06 #5
using late binding:

'as first line put 'Option Strict Off' for late binding
Dim o As Object = CreateObject("MSScriptControl.ScriptControl")
o.Language = "VBScript"
MsgBox(o.Eval("1+1"))
another way using reflection (works also with C#):

Dim expression As String = "1+1"
Dim scriptControl As Object = CreateObject("MSScriptControl.ScriptControl")
scriptControl.GetType.InvokeMember("Language", BindingFlags.SetProperty, Nothing, scriptControl, New Object() {"VBScript"}, Nothing)
Dim value As Object = scriptControl.GetType.InvokeMember("Eval", BindingFlags.InvokeMethod, Nothing, scriptControl, New Object() {expression})
MsgBox(value.ToString)

Personally I rather skip the reflection hassle and use late binding, not for the entire project, but only for one file where all classes go that use reflection.
Mar 3 '07 #6
This isn't an answer to your question but when I think about the need to
EVAL() scripts I have been considering hosting a Powershell instance (in
your app, non visually). Obviously, this would only be effective where
scripts don't already exist and you aren't protecting an existing body of
work.

It does appear that Powershell is the next generation of scripting on the
MSFT platform.

http://www.microsoft.com/windowsserv...l/default.mspx

jeff

"stax" <no****@nomail.nowrote in message news:es**********@online.de...
using late binding:

'as first line put 'Option Strict Off' for late binding
Dim o As Object = CreateObject("MSScriptControl.ScriptControl")
o.Language = "VBScript"
MsgBox(o.Eval("1+1"))
another way using reflection (works also with C#):

Dim expression As String = "1+1"
Dim scriptControl As Object =
CreateObject("MSScriptControl.ScriptControl")
scriptControl.GetType.InvokeMember("Language", BindingFlags.SetProperty,
Nothing, scriptControl, New Object() {"VBScript"}, Nothing)
Dim value As Object = scriptControl.GetType.InvokeMember("Eval",
BindingFlags.InvokeMethod, Nothing, scriptControl, New Object()
{expression})
MsgBox(value.ToString)

Personally I rather skip the reflection hassle and use late binding, not
for the entire project, but only for one file where all classes go that
use reflection.

Mar 4 '07 #7
do you have sample code for this?

Jeff Jarrell wrote:
This isn't an answer to your question but when I think about the need to
EVAL() scripts I have been considering hosting a Powershell instance (in
your app, non visually). Obviously, this would only be effective where
scripts don't already exist and you aren't protecting an existing body of
work.

It does appear that Powershell is the next generation of scripting on the
MSFT platform.

http://www.microsoft.com/windowsserv...l/default.mspx
Mar 4 '07 #8
I haven't actually coded to this. I was thinking about this as a way to
provide extensibility to the customer in a winforms app. Something like
providing a hook so that when a button a click there would be an opportunity
to provide a script there.

Aside from just looking and learning what a powershell script is, you can
start here for how to host powershell in your app.
http://msdn2.microsoft.com/en-us/library/ms714459.aspx

If you take a listen at some his old shows you can get a feel for what
powershell is all about.
http://www.hanselminutes.com/
"stax" <no****@nomail.nowrote in message news:es**********@online.de...
do you have sample code for this?

Jeff Jarrell wrote:
>This isn't an answer to your question but when I think about the need to
EVAL() scripts I have been considering hosting a Powershell instance (in
your app, non visually). Obviously, this would only be effective where
scripts don't already exist and you aren't protecting an existing body of
work.

It does appear that Powershell is the next generation of scripting on the
MSFT platform.

http://www.microsoft.com/windowsserv...l/default.mspx

Mar 4 '07 #9

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

Similar topics

7
by: J. Hall | last post by:
Hi dudes, Got a simple webpage, with three numeric text input boxes, the idea being that the user is asked to insert percentages of their business around the world... UK, Europe, Other ...
4
by: Geoff Cox | last post by:
Hello, No doubt this is simple but I cannot see how to do it ... I have a variable called situation_number with a series of values 1, 2, 3 etc. I would like to have a series of variables...
2
by: Eniac | last post by:
*argh* ... *pull hairs* I've recently started developing from ASP to ASP.NET The switch was fairly smooth since i had done some VB.net before ... then came...FORMS! :) I find it astounding...
4
by: uday.sen | last post by:
Hi, I need to convert a string from UTF8 to wide character (wchar_t *). I perform the same in windows using: MultiByteToWideChar(CP_UTF8, 0, pInput, -1, pOutput, nLen); However, in linux...
7
by: Helpful person | last post by:
I am new to Javascript and have a fairly straightforward question. I am trying to use an image as a link to open a new page with the onmouseclick event. In general this seems to work fine with...
1
by: =?ISO-8859-1?Q?Tor_Erik_S=F8nvisen?= | last post by:
Hi, A while ago I asked a question on the list about a simple eval function, capable of eval'ing simple python constructs (tuples, dicts, lists, strings, numbers etc) in a secure manner:...
11
by: Stef Mientki | last post by:
hello, I need to translate the following string a = '(0, 0, 0, 255), (192, 192, 192, 255), True, 8' into the following list or tuple b = Is there a simple way to to this. (Not needed...
7
by: bvdp | last post by:
I'm finding my quest for a safe eval() quite frustrating :) Any comments on this: Just forget about getting python to do this and, instead, grab my set of values (from a user supplied text file)...
10
by: Gordon | last post by:
I have a script that creates new objects based on the value of a form field. Basically, the code looks like this. eval ('new ' + objType.value + '(val1, val2, val3'); objType is a select with...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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
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...

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.