Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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
Arrays 如何声明非标准数组属于类?_Arrays_Vba_Class - Fatal编程技术网

Arrays 如何声明非标准数组属于类?

Arrays 如何声明非标准数组属于类?,arrays,vba,class,Arrays,Vba,Class,我有一门VBA课程: Option Explicit Public Re As Double 'Real Public Im As Double 'Imaginary Public Function CZ_Sqt(Z As Complex, Exp As Integer) As Variant Dim Table() As Complex Dim i As Integer If Exp > 0 Then ReDim Preserve Table(

我有一门VBA课程:

Option Explicit

Public Re As Double 'Real
Public Im As Double 'Imaginary


Public Function CZ_Sqt(Z As Complex, Exp As Integer) As Variant  
   Dim Table() As Complex
   Dim i As Integer

   If Exp > 0 Then
       ReDim Preserve Table(0 To Exp - 1)
       Set Table(UBound(Table)) = New Complex

   Else: Exit Function
   End If

   For i = 0 To UBound(Table)
      Table(i).Re = 1
      Table(i).Im = 1
   Next i
   set CZ_Sqt = Table 

End Function
在模块中:

Sub asd()
    Dim K As Complex
    Dim A As Variant

    Set K = New Complex


    K.Re = 1
    K.Im = 3
    Set A = K.CZ_Sqt(Z, 5)
end sub
  • 如何在步骤中“设置”所有变量“表”? 在示例中的解决方案中,只设置了元素表(4),而忽略了其他元素
  • 如何将这个变量“Table”返回到函数名“CZ_Sqt”? 我的建议不起作用
  • 如何将数组复杂类型的变量“CZYQSt”传递给变量“A”?
    您正在使用与对象和对象集合相同的类

    我将功能分为两类:

    • 复杂的
    • ComplexCollection-包含复杂类的集合
    编辑:ComplexCollection中没有重复的签入。在ComplexCollection.Retrieve中添加并存在签入

    复杂的

    Option Explicit
    
    Public Re As Double
    Public Im As Double
    
    复合收集

    Option Explicit
    
    Dim oCol As Collection
    
    Public Function Create(pRe As Double, pIm As Double) As Complex
        Dim oResult As Complex
        Set oResult = New Complex
        oResult.Re = pRe
        oResult.Im = pIm
    
        Set Create = oResult
    End Function
    
    Public Sub Add(pComplex As Complex, pKey As String)
         oCol.Add pComplex, pKey
    End Sub
    
    Public Function Retrieve(pKey As String) As Complex
         Set Retrieve = oCol(pKey)
    End Function
    
    Private Sub Class_Initialize()
        Set oCol = New Collection
    End Sub
    
    Private Sub Class_Terminate()
        Set oCol = Nothing
    End Sub
    
    Test.bas

    Public Sub TestCollection()
        Dim oCL As ComplexCollection
        Dim oC As Complex
    
        Set oCL = New ComplexCollection
    
        Set oC = oCL.Create(1, 2)
        Debug.Print oC.Im, oC.Re
    
        oCL.Add oC, "1"
    
        Set oC = Nothing
        Set oC = oCL.Retrieve("1")
    
        Debug.Print oC.Im, oC.Re
    
    End Sub