473,666 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2163
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.comw rote 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(expres sion)
{
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.Evalua te(expr), Double)

Console.WriteLi ne("{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.coms chrieb:
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.d e/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.d e/group/microsoft.publi c.dotnet.langua ges.csharp/msg/9e95759b54a323a 7>

--
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(expres sion)
{
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.Evalua te(expr), Double)

Console.WriteLi ne("{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.jscri pt.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("M SScriptControl. 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("M SScriptControl. ScriptControl")
scriptControl.G etType.InvokeMe mber("Language" , BindingFlags.Se tProperty, Nothing, scriptControl, New Object() {"VBScript"} , Nothing)
Dim value As Object = scriptControl.G etType.InvokeMe mber("Eval", BindingFlags.In vokeMethod, Nothing, scriptControl, New Object() {expression})
MsgBox(value.To String)

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("M SScriptControl. 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("M SScriptControl. ScriptControl")
scriptControl.G etType.InvokeMe mber("Language" , BindingFlags.Se tProperty,
Nothing, scriptControl, New Object() {"VBScript"} , Nothing)
Dim value As Object = scriptControl.G etType.InvokeMe mber("Eval",
BindingFlags.In vokeMethod, Nothing, scriptControl, New Object()
{expression})
MsgBox(value.To String)

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
1764
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 Obviously this mustn't exceed 100% and so I OnChange I simply want to check that all three boxes have a value, and if so sum them up and alert the user
4
1213
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 situation-1, situation-2 etc where the numbers 1 and 2 come from the situation_number variable.
2
2277
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 at how difficult it has become to control a form, something that was so dead easy in ASP.
4
22019
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 this API is not available. However, there exists mbstowcs() API, which converts multibyte string to wide character. But will this API convert UTF8 encoded string to wide character? Or this
7
1657
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 the open statement. I wish to use the same script at various places in my web and hence wish to pass to the javascript function the URL location and the width and height of the new page. I am having no luck trying to get the open statement to...
1
2212
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: http://groups.google.com/group/comp.lang.python/browse_thread/thread/58a01273441d445f/ also pointed to a simple eval function by Fredrik Lundh: http://effbot.org/zone/simple-iterator-parser.htm. His solution, using module tokenize, was short and...
11
1339
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 now, but might need it in the future: even deeper nested
7
242
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) and call an external program like 'bc' to do the dirty work. I think that this would avoid someone from embedding os.system("rm ...") in what I thought would be a math expression and having it maybe do damage? Perhaps I'm getting too paranoid in...
10
494
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 the different types of objects you can create as values. I really don't like using eval, and it's causing problems, like if I do something like the following:
0
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5664
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1775
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.