By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,140 Members | 1,277 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,140 IT Pros & Developers. It's quick & easy.

Converting String Value to a Formula for calculation?

P: n/a
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.
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
Nov 20 '05 #2

P: n/a
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
Nov 20 '05 #3

P: n/a
* "SiewSa" <st***********@kerks.com> 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/>
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.