-
September 18th, 2013, 02:10 PM
#1
evaluate string as line of code
Hi all,
Firstly, I apologise if I am threading old water here - I had a brief search but could not find what I was looking for....
I want to know if it is possible to evaluate a text string as if it is actual code, e.g.
string equation = "";
for (int i = 1; i <= 2; i++)
{
equation += @"Convert.ToInt16(txtValue" + i.ToString() + @".Text) +";
}
equation += " 0";
lblEquals.Text = equation;
output string: "Convert.ToInt16(txtValue1.Text) + Convert.ToInt16(txtValue2.Text) + 0"
Basically, I want to evaluate the output string, as generated by the loop, as c# code as if I had just entered:
int16 value = Convert.ToInt16(txtValue1.Text) + Convert.ToInt16(txtValue2.Text) + 0;
I will not know, until run time, how many variables there are going to be but they will all be similar to txtValuen.Text
Is this possible or am I barking up the wrong tree?
-
September 18th, 2013, 03:09 PM
#2
Re: evaluate string as line of code
Most likely barking up the wrong tree.
Why do want to do this?
-
September 18th, 2013, 03:28 PM
#3
Re: evaluate string as line of code
I am trying to write an ICM calculator that processes values based the inputs of a series of a series of boxes.
The problem is that the process is pretty complicated and needs to be processed relative to previous calculations.
Normally an algorithm is used, but I think that I can do it with formula's if I can build them independently and then process them.
-
September 19th, 2013, 10:40 AM
#4
Re: evaluate string as line of code
Have you tried searching for 'expression evaluation'.
-
September 21st, 2013, 04:13 AM
#5
Re: evaluate string as line of code
Thanks zips - I will definitely check that out as it looks promising! It was partly the search term that I was struggling with....
I have since moved on to reading the text boxes into arrays and am trying to process them that way but I may be able to go back to the formula idea....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|