I would like to pass in a few paramweters into a function and parse out an executable if statement without using a Case statement for each possibility.
For instance I would like to pass ">=" into a function and then string it into an if statement without doing this
Case OperatorParameter
Case ">="
if xxx >= yyy
etc..
Can this be done??
Thanks for any help
Mike GeehPosted Dec 19, 2007, 11:19 AM
Thanks alot Alan.
I think there is alot I can do with this.
MG
AlanPosted Dec 19, 2007, 10:02 AM
There's no Eval functionality built into the VB.Net language or the .NET framework themselves.
However, if you add a reference to the Microsoft Script Control to your project, then you can use the Eval() function in VBScript. Here's a quick example:
Module
Module1 Dim sc As New MSScriptControl.ScriptControl() Sub Main()sc.Language =
"VBScript" Dim result1 As Boolean = Test(">=", 4.0, 2.0) Dim result2 As Boolean = Test(">=", 2.0, 4.0)Console.WriteLine(result1)
Console.WriteLine(result2)
Console.ReadLine()
End
Sub Public Function Test(ByVal op As String, ByVal operand1 As Double, ByVal operand2 As Double) As Boolean Return sc.Eval(operand1.ToString() & op & operand2.ToString()) End FunctionEnd
Module