我正在做一个程序,它从我在项目中的静态代码元素创建动态代码,如变量,数组,子例程,函数等......
例如,代码如下:
Do
id = id + 1
bandera = bandera + 1
arreglo = valvula(id) 'this is a function
Loop Until (bandera = 100)
id,bandera,arreglo和valvula是我程序的静态代码元素
在互联网上冲浪我发现我可以使用msscriptcontrol在vb.net中使用脚本,这就是为什么我做了这个例子:
Option Strict Off
Option Explicit On
Imports System.Collections.Generic
Public Class Form1
Inherits System.Windows.Forms.Form
Dim VBScript As MSScriptControl.ScriptControl
Public valor As Double
Public VBCode As String
Public otro(2) As Double
Public nuevo As New Dictionary(Of Integer, nodo)
Public prueba As New nodo
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
On Error GoTo line1
VBScript.AddCode(VBCode)
Exit Sub
line1:
MsgBox(Err.Number & Err.Description, MsgBoxStyle.Critical, "error")
Err.Clear()
End Sub
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
Dim prueba As New nodo
otro(0) = 0
prueba.uno = 1
prueba.dos = 1
nuevo.Add(1, prueba)
VBScript = New MSScriptControl.ScriptControl
VBScript.Language = "VBScript"
VBScript.AddObject("Form1", Me)
VBScript.AllowUI = True
End Sub
Function funcion(ByVal valores As Double) As Double
valores = valores + 1
funcion2()
Return valores
End Function
Function valvula(ByVal dato1 As Integer, ByVal dato2 As Integer, ByVal dato3 As Integer) As Double()
dato1 = dato1 + 1
dato2 = dato2 + 1
dato3 = dato3 + 1
valvula = New Double() {dato1, dato2, dato3}
End Function
End Class
Public Class nodo
Public uno As Integer
Public dos As Integer
End Class
Module Module1
Public variable1 As Double = 120
Public Sub funcion2()
variable1 = variable1 + 1
MsgBox(variable1)
End Sub
End Module
但我有几个问题:
1.-当我尝试编译并执行这种行时:
form1.otro(0) = 0
MsgBox(form1.nuevo(1).dos)
我的程序显示以下错误:“错误的参数数量或无效的属性赋值”,我想知道为什么我不能使用括号来处理我从“form1”调用的元素的特定索引。< / p>
2.-我想知道如何调用标准vb模块中声明的公共变量,函数或其他内容等元素。