0
下面是一些代碼在運行時執行的代碼:執行運行時代碼參數
Dim SourceCode As String = txtCode.Text
Dim Dlls() As String = {"System.dll", "System.Core.dll", "System.Data.dll", "System.Windows.Forms.dll"} 'Any referenced dll's
Dim Compiler As New VbCompiler(SourceCode, Dlls)
Dim CodeAssembly As Assembly = Compiler.Compile
If Compiler.Successful Then
Dim instance As Object = CodeAssembly.CreateInstance("TestCode.Class1")
Dim CodeType As Type = instance.GetType
Dim Info As MethodInfo = CodeType.GetMethod("ShowMessage")
Info.Invoke(instance, Nothing)
Else
For Each i As CompilerError In Compiler.Errors
MsgBox(i.ErrorText)
Next
End If
txtCode.text =:
這工作完全。我想知道如何將參數傳遞給函數。即
txtCode.text =:
Imports System.Windows.Forms
Namespace TestCode
Class Class1
Sub ShowMessage(ByVal x As String)
MessageBox.Show(x)
End Sub
End Class
End Namespace
我想「用一個字符串作爲參數,函數的例子(‘測試’)運行「ShowMessage
我很確保它是在下面幾行:
Dim Info As MethodInfo = CodeType.GetMethod("ShowMessage")
Info.Invoke(instance, Nothing)
但我不能得到它的工作
子ShowMessage(BYVAL X作爲字符串) MessageBox.Show(X) 結束小組 –
@SimonCanning - 對不起!你想說點什麼嗎?看看Invoke()方法的第二個參數。這樣你可以傳遞一個參數給ShowMessage。 – adatapost
太棒了。謝謝。 –