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
End If
MsgBox(val3_calculated)
Error:
But it throws an error saying that I am not using any databind control.
Concerns:
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).
Thank you:
Any help is highly appreciated. It is kinda urgent. Thanks a lot.
KnowledgeisW...
0 Points
10 Posts
Do I have to use an Eval operator here?
Apr 21, 2012 07:21 PM|LINK
Hi everyone,
Problem:
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
End If
MsgBox(val3_calculated)
Error:
But it throws an error saying that I am not using any databind control.
Concerns:
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).
Thank you:
Any help is highly appreciated. It is kinda urgent. Thanks a lot.