Last post Apr 21, 2012 08:36 PM by Careed
Apr 21, 2012 07:21 PM|KnowledgeisWealth|LINK
I have to calculate values of several equations in an application. For example, one these equations could be:
d = a + b*z + c*z (this is what is being displayed to the user, assume that 'a', 'b' and 'c' are provided as textboxes, assume that z is a hardcoded value for now)
Now, the user could enter a=1.5, b= -0.5 and c = -0.6 (or even 'a' could be negative)
So, I just tried a sample code for simple values but to no avail...
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim val1, val2, val3_calculated, first, second As String
first = "8"
second = "3"
Dim arr(10) As String
arr(1) = "-"
arr(2) = "+"
val1 = TextBox1.Text
val2 = val1.Substring(0, 1)
If arr.Contains(val2) Then
val3_calculated = Eval("return first val2 second") // I tried using '&' operator as well
But it throws an error saying that I am not using any databind control.
First of all, is it necessary to use this "eval" operator in here? Is there any way to keep "-0.5" with the sign in asp.net using vb? Can I do something else to make it work? (I would prefer a small piece of code for this).
Any help is highly appreciated. It is kinda urgent. Thanks a lot.
Apr 21, 2012 08:36 PM|Careed|LINK
First of all, the Eval method is used to evaluate variables in conjunction with server controls.
Secondly, you would normally use an event handler like a Button Click as the method to either populate controls within your ASPX page or save to your data source.
Lastly, your statement to "evaluate" is not login as this is a subroutine method that returns nothing.
Given this, what are you trying to do?