Avatar of lelandgaunt
lelandgaunt asked on

How do I eval with Scriptcontrol an own function in VB.NET?

Hi!

I try to evaluate my own function with Scriptcontrol (vbscript language), but always got this error:
Type mismatch: 'TestMethod'
(code below)

Anyone could help?

Sorry for my weak english.

Robert

Imports MSScriptControl
 
Module Module1
 
    Public Sub Main()
        Dim scTemp As New ScriptControl()
        Dim blnResult As Boolean
 
        Try
            scTemp.Language = "VBScript"
            blnResult = CType(scTemp.Eval("TestMethod(True)"), Boolean)
        Catch ex As Exception
            MsgBox(ex.Message & vbCrLf & ex.StackTrace)
        End Try
    End Sub
 
    Public Function TestMethod(ByVal blnParam As Boolean) As Boolean
        Return blnParam
    End Function
End Module

Open in new window

Visual Basic.NET

Avatar of undefined
Last Comment
lelandgaunt

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Mike Tomlinson

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Mike Tomlinson

ASKER
lelandgaunt

Thanks for the reply!

My goal is:
(2) Evaluate an arbitrary line of code stored in a String.
This String contains math expression and own Sub/Function simultaneously.

Can Script Control evaluate this?
Mike Tomlinson

I don't think it can do it simultaneously...but what you can do is use the AddCode() method first to add the code portion into the ScriptControl.  Then use one of the methods listed here to run your code:
http://support.microsoft.com/kb/184740
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER
lelandgaunt

Thanks for the description.
It was very helpful to understand the Script Control.
My solution is to split the String two pieces. Then for math expr -> eval, for own Sub/Function -> Reflection