Home  |  Index  |  Dotnet4all Snippets  |  Submit resources
About  |  Mail us  
Dotnet4all Logo

  Converting String Value to a Formula for calculation? (Thursday, September 02, 2004)




Found the following interesting discussion in the Newsgroups:

Converting String Value to a Formula for calculation?
by:SiewSa

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:
by:Cor Ligthert

 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:
by:Cor Ligthert

 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:
by:hirf-spam-me-here@gmx.at (Herfried K. Wagner [MVP])

 
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/>








 
Previous Posts
    - Microsoft Office Document Image Writer & Vb.Net
    - AddRange method for CheckedListBox
    - Any way to extract certain bytes from the remote f...
    - Date format problem with vb.net
    - Dynamic Expression Evaluation
    - Finding the Printable area
    - How to add a dimension to an array in VB.NET
    - How to access a Specific Mailbox on Exchange
    - DataGrids and obtaining information from them
    - Turn of time Automatic update in DateTimePicker Co...

Archives
    - 08/01/2004 - 08/08/2004
    - 08/08/2004 - 08/15/2004
    - 08/15/2004 - 08/22/2004
    - 08/22/2004 - 08/29/2004
    - 08/29/2004 - 09/05/2004
    - 09/05/2004 - 09/12/2004
    - 09/12/2004 - 09/19/2004
    - 09/19/2004 - 09/26/2004
    - 09/26/2004 - 10/03/2004
    - 10/03/2004 - 10/10/2004
    - 01/02/2005 - 01/09/2005
    - 01/09/2005 - 01/16/2005
    - 01/30/2005 - 02/06/2005
    - 01/01/2006 - 01/08/2006


Disclaimer & Terms of Use  | DotNet4All.Com concept & © 2004 - 2007 by  Zelders²  - Holland