Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 希望使用变量访问类成员_Excel_Vba - Fatal编程技术网

Excel 希望使用变量访问类成员

Excel 希望使用变量访问类成员,excel,vba,Excel,Vba,我已经定义了一个类clsPowerAtt Public customerName As String Public customerSoc As String sub test () Dim oPowerEntry As New clsPowerAtt dim members(5) as string members(0) = customerName members(1) =customerSoC dim entry as variant for each en

我已经定义了一个类clsPowerAtt

Public customerName As String
Public customerSoc As String


sub test ()
  Dim oPowerEntry As New clsPowerAtt

  dim members(5) as string
  members(0) = customerName
  members(1) =customerSoC
  dim entry as variant

  for each entry in members

    oPowerEntry .entry = "foo"

  next each
end sub
我想遍历一个定义类成员的数组,这样我就不需要直接调用。它不喜欢使用变量来指向类成员

oPowerEntry .entry = "foo"

如何告诉vba评估条目

使用类构造函数。在本例中,构造函数称为“init”(用于初始化)

您的私有类属性

Private pinp1 As Double
Private pinp2 As Double
Private pinp3 As Double
Private pinp4 As Double
Private pinp5 As Double
还有你的构造器。在这里,您可以将所有五个(或任意多个)属性作为Public Sub的参数传递。当然,您需要用您的和数据类型替换my属性的名称。这只是一个基本构造函数的示例

Public Sub init(ByVal inp1 As Variant, ByVal inp2 As Variant, ByVal inp3 As Variant, _
            ByVal inp4 As Variant, ByVal inp5 As Variant)
    '
    ' set the private class variables to your parameters
    pinp1 = CDbl(inp1)
    pinp2 = CDbl(inp2)
    pinp3 = CDbl(inp3)
    pinp4 = CDbl(inp4)
    pinp5 = CDbl(inp5)
End Sub

你试过使用枚举吗?虽然我不确定这是否可能。我通常使用类构造函数来设置类对象属性。