PC Review


Reply
Thread Tools Rate Thread

Converting String Value to a Formula for calculation?

 
 
SiewSa
Guest
Posts: n/a
 
      13th Apr 2004
I have come to a situation that I need to use the result of a string
variable as a formula for performing calculation.

As an example below:

Dim X As Integer

Dim Y As Integer

Dim Result As Integer

Dim Formula As String = "X + Y"

X = 3

Y = 5

Result = Formula

MessageBox.Show(Result)

I know that the above example is not working but I am appreciate if someone
out there can help me on that.

I think I have gone through some similar questions inside the newsgroup but
I am not too sure on the solutions. Many thanks to someone out there who is
answering the above question again and if possible, give me an example.

Thank you.


 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      13th Apr 2004
Hi SiewSA,

The most used are I think
(1+1).toString that is the same as "2"
Dim myvalue as integer = Cint("2")
Dim myvalue as double = Cdbl("2")

I hope this helps?

Cor


 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      13th Apr 2004
Hi SiewSa,

I see now you want an Eval function, that is not build in.

However you can read here what is written about that in this newsgroup.

http://tinyurl.com/2fznf

Cor


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      13th Apr 2004
* "SiewSa" <(E-Mail Removed)> scripsit:
> I have come to a situation that I need to use the result of a string
> variable as a formula for performing calculation.
>
> As an example below:
>
> Dim X As Integer
>
> Dim Y As Integer
>
> Dim Result As Integer
>
> Dim Formula As String = "X + Y"
>
> X = 3
>
> Y = 5
>
> Result = Formula
>
> MessageBox.Show(Result)
>
> I know that the above example is not working but I am appreciate if someone
> out there can help me on that.
>
> I think I have gone through some similar questions inside the newsgroup but
> I am not too sure on the solutions. Many thanks to someone out there who is
> answering the above question again and if possible, give me an example.


Samples:

<URL:http://www.codeproject.com/useritems/evaluator.asp>
<URL:http://www.codeproject.com/csharp/livecodedotnet.asp>

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

If you have a DevX account:

<URL:http://www.devx.com/codemag/Article/10352/0/page/1/>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting calculation expressed as text into a formula Paul Stagg Microsoft Excel Misc 3 12th Jan 2009 05:51 PM
Converting a Formula stored as String to real Formula BlueD Microsoft Excel Worksheet Functions 3 14th Jan 2008 07:48 PM
Formula or string - calculation in a cell John61 Microsoft Excel Discussion 1 11th Sep 2007 04:33 AM
Converting a String to Calculation to Produce a Sum Dominic Smith via AccessMonster.com Microsoft Access VBA Modules 2 1st Feb 2005 11:13 PM
Converting string formula to mathematical formula VM Microsoft C# .NET 5 6th Jul 2004 08:23 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:41 AM.