Is there a general way to check a string...
-
Is there a general way to check if an if statement is semantically correct in vb.net?. For example: Checking this: input string: Cost = 20 + Quantity - Discount and Cost = 49 or it could be: Cost = 20 * Quantity / Discount and Cost = 49 Note that Cost, Quantity, and Discount is an integer variables. Thanks in advance for your help. John
-
Is there a general way to check if an if statement is semantically correct in vb.net?. For example: Checking this: input string: Cost = 20 + Quantity - Discount and Cost = 49 or it could be: Cost = 20 * Quantity / Discount and Cost = 49 Note that Cost, Quantity, and Discount is an integer variables. Thanks in advance for your help. John
This question doesn't have an answer until it's put into the context of how it's being used... Are you saying that you want to check to see if this code is correct before being compiled? Or are you trying to parse this string and evalutate it? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
This question doesn't have an answer until it's put into the context of how it's being used... Are you saying that you want to check to see if this code is correct before being compiled? Or are you trying to parse this string and evalutate it? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Basically, the string is an if statement. For example: if Cost = 20 * Quantity / Discount and Cost = 49 then.... This is an input from user. And i'm trying to parse the string and check the "if" part only. John
Let me get this straight... This is your VB.NET code and your trying to do something like this:
'Get some user input and put it in a variable. Then evaluate the expression...
Dim strInput As String = "Cost = 20 * Quantity / Discount and Cost = 49"
EvaluateUserExpression(strInput)
.
.
.Public Function EvaluateUserExpression(ByVal strExpression As String) As Boolean
If strExpression Then
Return True
Else
Return False
End If
End FunctionNow, if I understand you correctly, the Cost, Quantity, and Discount terms are actual variables inside your code. Correct????? If this is true, then what you want to do can't be done using a simple if statement. You must parse up and validate the expression term-by-term and evaluate it along the way. You would ahve to check to see if the Cost/Quantity/Discount variables exist in your code, handle the equals signs and the operators yourself. You're looking for expression parsing techniques that, if covered in breif, are much too large to be taught over the forums. Google for 'VB mathematical expression parser' and you'll come up with tons links on various articles, techniques, some source code... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome