0

我想以数组具有的数组元素的数量从模块生成元素(复选框和文本框)到用户窗体。例子:

  • 数组4()
  • array4(1): "彼得迈尔"
  • array4(2): "乔·加纳"
  • array4(3): "菲尔大师"
  • 等等

  • 数组2()

  • 数组2(1):2
  • 数组2(1):2
  • 数组2(2):6
  • 数组2(3):160
  • 等等

两个数组始终具有相同数量的数组。

用户窗体应显示余木:

  1. 复选框 / Textfield.Text = Peter Meier / Textfield.Text = 2
  2. 复选框 / Textfield.Text = Joe Garner / Textfield.Text = 6
  3. 等等

等等问候,Yab86

4

1 回答 1

0

将两个值存储在同一个数组中可能更优雅?

array(1,1) = "Peter Meier"
array(1,2) = "2"

array(2,1) = "Joe Garner"
array(2,2) = "2"

ETC...

至于你的问题,可能是这样的:

Sub Stuff()
    Dim vrData(2, 1) As Variant ' or vrData() and redim later
    Dim ctControl As Control
    Dim intPosX, intPosY As Integer
    Dim ufForm As BlankForm ' i.e. a blank userform you create first


    vrData(0, 0) = "Whatever"
    vrData(0, 1) = "3"
    vrData(1, 0) = "Something"
    vrData(1, 1) = "2"
    vrData(2, 0) = "Horse"
    vrData(2, 1) = "7"

    intPosX = 20
    intPosY = 20

    Set ufForm = New BlankForm

    For i = 0 To UBound(vrData, 1)
        Set ctControl = ufForm.Controls.Add("Forms.CheckBox.1")
        With ctControl
            .Caption = vrData(i, 0)
            .Left = intPosX
            .Top = intPosY
        End With

        Set ctControl = ufForm.Controls.Add("Forms.TextBox.1")
        With ctControl
            .Text = vrData(i, 1)
            .Left = intPosX + 100
            .Top = intPosY
        End With

        intPosY = intPosY + 20
    Next

    ufForm.Show
End Sub
于 2013-08-30T09:27:40.970 回答