none
vb.net scriptcontrol RRS feed

  • 问题

  •     Public Sub aa()
            MsgBox("执行它")
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim ScriptControl As New MSScriptControl.ScriptControl
            ScriptControl.Language = "VBScript" 
            ScriptControl.AddObject("me", Me)
            ScriptControl.AddCode("me.aa()") 
        End Sub

    请问这段代码在vb.net里为什么会弹错?

    2019年6月30日 17:19

全部回复

  • Hi,

    添加代码ComVisible(True),修改代码:

    Imports System.Runtime.InteropServices
    
    <ComVisible(True)>
    Public Class Form1
        Public Sub aa()
            MsgBox("执行它")
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim ScriptControl As New MSScriptControl.ScriptControl
            ScriptControl.Language = "VBScript"
            Dim f1 As New Form1
            ScriptControl.AddObject("f1", f1)
            ScriptControl.AddCode("f1.aa()")
        End Sub
    End Class

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.







    2019年7月1日 8:20
  • 非常感谢,测试通过,谢谢
    2019年7月1日 13:14
  • Hi,

    如果问题已经解决,请将正确答案mark,谢谢。

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2019年7月2日 1:08