Hi Maurice
Here is something I use
<code>
Public NotInheritable Class Evaluator
Private Shared WithEvents m_ScriptControl As
MSScriptControl.ScriptControlClass
Shared Sub New()
m_ScriptControl = New MSScriptControl.ScriptControlClass
m_ScriptControl.Language = "VBScript"
m_ScriptControl.AllowUI = False
End Sub
Public Shared Function Evaluate(ByVal s As String, ByVal decimalPlaces
As Integer) As Double
Return Decimal.Round(Convert.ToDecimal(Evaluate(s)), decimalPlaces)
End Function
Public Shared Function Evaluate(ByVal s As String) As Double
Dim r As Double
m_ScriptControl.Reset()
' Example of executing code
''m_ScriptControl.ExecuteStatement("Dim m")
''m_ScriptControl.ExecuteStatement("m = 5")
' Example of manipulating a form
''m_ScriptControl.AddObject("DotnetForm", Me)
''m_ScriptControl.ExecuteStatement("dotnetform.wid th =
dotnetform.width + 10")
Try
r = CDbl(m_ScriptControl.Eval(s))
Catch ex As Exception
Dim ee As EvaluationException
ee = New EvaluationException(ex.Message)
ee.Description = m_ScriptControl.Error.Description
ee.Column = m_ScriptControl.Error.Column
ee.Number = m_ScriptControl.Error.Number
ee.Source = m_ScriptControl.Error.Source
ee.Text = m_ScriptControl.Error.Text
Throw ee
End Try
Return r
End Function
End Class
</code>
I call Evaluator.Evaluate(...) with a string that I want to evaluate,
optionally with a number of decimal places. EvaluationException is my custom
exception class, but you could make up your own.
HTH
Charles
"Maurice" <hm*****@nospam.nospam> wrote in message
news:Xn****************************@194.109.133.24 2...
"Armin Zingler" <az*******@freenet.de> wrote in news:OrGv#YjNGHA.428
@tk2msftngp13.phx.gbl:
Creating an object by class name
Hi Armin,
sorry, indeed creating an object by class name.
It's possible that in future some names may change and I don;t want to
change this function then. That's why I don't want a select case statement
to declare a new form.
But isn't there something like the Eval function in VBScript that you can
use?
i.e.:
Dim intA as integer, intB as integer, intC as integer
intA = 5
intB = 10
Eval("intC = intA * intB")
The string value "intC = intA * intB" would then be executed as code and
intC would have the value 50.