这是我的代码 Function GenerateInterface()Dim ObjectsArray() As VB.ControlDim TmpCtrl As VB.ControlReDim ObjectsArray(1)For Each TmpCtrl In Me.Controls If TmpCtrl.Container Is frConfigVars(0) Then Set ObjectsArray(UBound(ObjectsArray)
Function GenerateInterface() Dim ObjectsArray() As VB.Control Dim TmpCtrl As VB.Control ReDim ObjectsArray(1) For Each TmpCtrl In Me.Controls If TmpCtrl.Container Is frConfigVars(0) Then Set ObjectsArray(UBound(ObjectsArray) - 1) = TmpCtrl ReDim Preserve ObjectsArray(UBound(ObjectsArray) + 1) End If Next TmpCtrl For i = 1 To UBound(Variables) - 1 'global array containing how many frames I need Load frConfigVars(i) frConfigVars(i).Left = 0 frConfigVars(i).top = frConfigVars(i - 1).top + frConfigVars(i - 1).Height frConfigVars(i).Visible = True For x = 0 To UBound(ObjectsArray) - 1 Set TmpCtrl = ObjectsArray(x) Load TmpCtrl(i) '<-- crashes here 'stuff to move and view new object Next x Next i End Function
它基本上加载到一个控件数组中,框架中存在的0索引对象让我在dinamycally加载它我需要多少次但我无法从变量本身加载一个新的控件.
我有点为什么加载崩溃,我猜TmpCtrl包含(例子)txtbox(0)而不是txtbox,我需要加载新对象,对吗?
如果是这样,我如何加载新控件?
我无法从头开始创建对象,因为它们中有很多并且定位会很糟糕
我不能用他们的名字给他们打电话,因为随着时间的推移,我会添加/删除一些东西,所以我不想再次触摸这个功能
谢谢
好吧,我其实是自己做的!要访问对象数组本身,我只需要更改
Set TmpCtrl = ObjectsArray(x)
成
Set TmpCtrl = Me.Controls(ObjectsArray(x).Name)