Hello guys.

I'm using a Microsoft Word form template to create objects in a form programatically, so depending on the information read by the program from the template.

So, I've got some fields where I store formula data for the form, in which I specify that the value for that field is obtained by multiplying other fields in the template. So I store in the string something like this:

"Text1.Text * Text2.Text"

So I need to convert these string values into variable calls to actually operate these values.

What would be the best way to do this?

VBA (or VB.NET) doesn't have any Eval function like you have in JavaScript.

I found this article: Evaluate string formulas in VB which uses Script Control's Eval function. The article's download link is outdated, here's correct link to Windows Script Control.

I didn't test it in anyway, so check it yourself if it is usable for you.

HTH

If you want to do a Math operations over some data, these data have to be a true numbers. You cannot do math operations over strings (like the text property provides of the textBox).
You can do:

int value1 = int.Parse(textBox1.Text);
int value 2 = int.Parse(textBox2.Text);
//put a result into 3rd textBox:
textBox3.Text = (value1 * value2).Tostring();

Hope this clears on which kind of data you can do math operations, and on which you cannot. You can do on all number types, like int, decimal, floaf, double,...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.