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

Let a user write an expression as a string and return a value

I'm using visual basic.net, I need to take in input a string containing an
expression and return the value, example:

"14=14" must return true
"14+14" must return 28
"8<4" must return false
Jul 21 '05 #1
3 1416
Hi Federico,

I believe you will have to do this manually the hard way by splitting
operators and numbers by presedence and possibly recursively.

On Fri, 21 Jan 2005 00:43:04 -0800, Federico Caselli
<Fe*************@discussions.microsoft.com> wrote:
I'm using visual basic.net, I need to take in input a string containing
an
expression and return the value, example:

"14=14" must return true
"14+14" must return 28
"8<4" must return false


--
Happy Coding!
Morten Wennevik [C# MVP]
Jul 21 '05 #2
"Federico Caselli" wrote:
I'm using visual basic.net, I need to take in input a string containing an
expression and return the value, example:


This is possible by generating code, compile it and execute, all at runtime!

I've done it, works like a charm! This article got me started:

http://www.odetocode.com/Code/80.aspx

Steven

- - -
Jul 21 '05 #3
Thank you. The class Evaluator is really what I need. Just one thing: I need
to evaluate a boolean expression, like "84 < 70" or "7 >=8". So I tried to
add the following method to the class Evaluator
-------------------------------------------------------------------------------------
public static bool EvalToBoolean(string statement)
{
string s = EvalToString(statement);
return bool.Parse(s.ToString());

-------------------------------------------------------------------------------------

When I try to use the method

blnRes = Evaluator.EvalToBoolean("7<8")

I get an exception.

Is there a way to make it work?

Thank you


"Steven Spits" wrote:
"Federico Caselli" wrote:
I'm using visual basic.net, I need to take in input a string containing an
expression and return the value, example:


This is possible by generating code, compile it and execute, all at runtime!

I've done it, works like a charm! This article got me started:

http://www.odetocode.com/Code/80.aspx

Steven

- - -

Jul 21 '05 #4

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

Similar topics

1
by: Jay Douglas | last post by:
I need help getting the collections to show up in the property window of a user control. I want to be able to edit the collection items just like any other asp.net control that has collection...
4
by: Moe Sizlak | last post by:
Hi There, I am trying to return the value of a listbox control that is included as a user control, I can return the name of the control but I can't access the integer value of the selected item,...
3
by: Marty McFly | last post by:
Hello, I have a control class that inherits from System.Web.UI.WebControls.Button. When I drag this control from the "My User Controls" tab in the toolbox onto the form, I want it to reflect the...
3
by: Federico Caselli | last post by:
I'm using visual basic.net, I need to take in input a string containing an expression and return the value, example: "14=14" must return true "14+14" must return 28 "8<4" must return false
10
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/acfctNZ_HV05186465.asp "If the value of the variant argument is Null, the Nz function returns the number zero or a...
4
by: a | last post by:
I'm having trouble testing a custom object. I've tried many different approaches. One is shown below. The XML below shows the state of the object and I'm trying to test for that state, ie there...
7
by: Tizzah | last post by:
What is wrong with that? regex = /^(http|https):\/\/+({1}+)*\.{2,5}(({1,5})?\/.*)?$/ if(field.hpage.value != regex.test(field.hpage.value)){ alert("Bad Homepage") field.hpage.focus()...
11
by: Steve | last post by:
Hi All, I'm having a tough time converting the following regex.compile patterns into the new re.compile format. There is also a differences in the regsub.sub() vs. re.sub() Could anyone lend...
7
by: rodchar | last post by:
hey all, for simplicity's sake i have a single textbox inside a user control. once i drag that user control onto my page is there a way to attach a binding expression to it at runtime? thanks,...
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...
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
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,...
0
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...

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.