473,405 Members | 2,154 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.

Calculations

Is there a way to make a calculation stored in a string. For example:

Dim A as string = "4 * 10 ^ 8"

Dim Result as Decimal = Calculate(A)
Oct 25 '07 #1
6 1271
"Pitaridis Aristotelis" wrote:
Is there a way to make a calculation stored in a string. For example:

Dim A as string = "4 * 10 ^ 8"

Dim Result as Decimal = Calculate(A)
I don't think so :(
Oct 25 '07 #2
Pitaridis Aristotelis wrote:
Is there a way to make a calculation stored in a string. For example:

Dim A as string = "4 * 10 ^ 8"

Dim Result as Decimal = Calculate(A)
There are many ways to do this, some better than others and some more
complex than others...

Try the following Google search which should provide some answers:

http://www.google.com/search?hl=en&q=%22vb.net%22+eval

--

(O)enone

Oct 25 '07 #3
On Oct 25, 3:51 am, "Pitaridis Aristotelis" <pitari...@hotmail.com>
wrote:
Is there a way to make a calculation stored in a string. For example:

Dim A as string = "4 * 10 ^ 8"

Dim Result as Decimal = Calculate(A)
As an alternative:

http://groups.google.com/group/micro...e=UTF-8&rnum=1

Be aware, that you will probably want to validate any expressions you
pass to this function, because it will run arbitrary jscript code.

--
Tom Shelton

Oct 25 '07 #4
? "Tom Shelton" <to*********@comcast.net?????? ??? ??????
news:11**********************@k35g2000prh.googlegr oups.com...
On Oct 25, 3:51 am, "Pitaridis Aristotelis" <pitari...@hotmail.com>
wrote:
>Is there a way to make a calculation stored in a string. For example:

Dim A as string = "4 * 10 ^ 8"

Dim Result as Decimal = Calculate(A)

As an alternative:

http://groups.google.com/group/micro...e=UTF-8&rnum=1

Be aware, that you will probably want to validate any expressions you
pass to this function, because it will run arbitrary jscript code.

--
Tom Shelton
I was looking for vb.net code which will handle the whole thing. I used
sometime an example that I downloaded from the internet but I can not find
it.
Oct 26 '07 #5
You are looking for an algorithm that's called a "recursive descent parser".
Doing this type of thing is an exercise that we had to do in programming
classes 35 years ago.

I'm a little bit amazed that something like this doesn't exist in the .Net
framework. Even in VBScript I think there's the "eval" function that might
have limited parsing capability. Still ... this is a good programming
exercise to learn how to write recursive functions.

If you want to create your own class function to do this go get a
fundamental programming book and study the chapters on recursion. I'd be
real surprised if you couldn't find a good writeup on how to do this.

-bwr-

"Pitaridis Aristotelis" <pi*******@hotmail.comwrote in message
news:47***********************@news.sunsite.dk...
Is there a way to make a calculation stored in a string. For example:

Dim A as string = "4 * 10 ^ 8"

Dim Result as Decimal = Calculate(A)

Oct 28 '07 #6
On Oct 26, 3:25 am, "Pitaridis Aristotelis" <pitari...@hotmail.com>
wrote:
? "Tom Shelton" <tom_shel...@comcast.net?????? ??? ??????news:11**********************@k35g2000prh.go oglegroups.com...


On Oct 25, 3:51 am, "Pitaridis Aristotelis" <pitari...@hotmail.com>
wrote:
Is there a way to make a calculation stored in a string. For example:
Dim A as string = "4 * 10 ^ 8"
Dim Result as Decimal = Calculate(A)
As an alternative:
http://groups.google.com/group/micro...languages.vb/m...
Be aware, that you will probably want to validate any expressions you
pass to this function, because it will run arbitrary jscript code.
--
Tom Shelton

I was looking for vb.net code which will handle the whole thing. I used
sometime an example that I downloaded from the internet but I can not find
it.- Hide quoted text -

- Show quoted text -
Why does it have to be VB.NET. With a few lines of JScript code
(a .net language), you can accomplish what you're asking.

If you simply want the experience of doing this sort of thing, then
great. It is a good programming exercise - I MIGHT even have some old
C++ and VB5 code somewhere that does this (I wrote the C++ code for an
exercise in school, and latter adapted it to VB5).

--
Tom Shelton
Oct 28 '07 #7

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

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
0
by: Rowan | last post by:
Howdy, I am having some trouble figuring out the best way to approach my problem with calculations. I think I should use a view but am having trouble with the structure. My view needs to...
4
by: Targa | last post by:
Trying to total some price fields in a form but doesnt work when all the referenced form fields dont exisit. This is for an invoice - pulled prom a database and the form doesnt always contain the...
11
by: lduperval | last post by:
Hi, I`m trying to do date calculations in three types of time zones: local, GMT and specified. The issue I am facing is that I need to be able to specify a date in the proper time zone, and I`m...
3
by: brian kaufmann | last post by:
Hi, I had sent this earlier, and would appreciate any suggestions on this. I need to make calculations for unemployment rate for three different data sources (A,B,C) for many countries and age...
3
by: John M | last post by:
Hi, I've been coming up against a failure of a report to display the result of a simple calculation. I have realised that this calculation cannot take place unless the field I am working on is...
0
by: SJM | last post by:
There is a database which has combo boxes to allow users to select values from pre-set lists of common specifications. The form allows users to enter values that are not in the dropdown lists....
13
by: fredrik.ryde | last post by:
Hi, I have a database which contains alot of finacial data. I want to retreive some data, run som calculations with it, nothing complex just simple arithmetic. I wonder if it's faster to let...
1
by: Grubsy4u | last post by:
Grubsy4u Newbie 7 Posts October 5th, 2007 11:31 AM #1 Report calculations --------------------------------------------------------------------------------
9
Catalyst159
by: Catalyst159 | last post by:
I have a form which is used to calculate residential Floor Area Ratio (FAR). The form is structured into seven parts as follows: Part A: Maximum FAR and Floor Area: Part B: Gross Floor Area of...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
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.