2017-05-17 22 views
0

我有以下多維數組結構輸出數組內容而不選擇各元件

Type Wedge 
    C407    As Long 
    C417    As Long 
    C507    As Long 
    C516    As Long 
    C607    As Long 
    C617    As Long 
    C707    As Long 
    C716    As Long 
    C807    As Long 
    C817    As Long 
    C907    As Long 
    C916    As Long 
End Type 

上面具有約35的元件將其

Global myWedge() As Wedge 
ReDim myWedge(99, 4) 

我已填充陣列,但現在要輸出的數組的內容添加到工作表中。以前在其他較小的陣列中,我已經輸出如下的每個元素。

'Output IOTT Number and Duration 
     For a = 1 To 4 
      If YGBL(x, a).IOTT > 0 Then sOutput.Cells(x + 4, IOTTCol) = YGBL(x, a).IOTT 
       IOTTCol = IOTTCol + 2 
      If YGBL(x, a).IOTTDUR > 0 Then sOutput.Cells(x + 4, IOTTDUR) = YGBL(x, a).IOTTDUR 
       IOTTDUR = IOTTDUR + 2 
     Next a 

但是,考慮到我只想循環元素的數量並將其放入表單中,而不必爲每個元素執行上述操作。

這可能

感謝

回答

1

使用功能....

Function PropertyOf(wedgeType As Wedge, index As Integer) As Long 
    Dim w As Long 

    With wedgeType 
    Select Case index 
     Case 1 
     w = .C407 
     Case 2 
     w = .C417 
     Case 3 
     w = .C507 
     .... 
    End Select 
    End With 
    PropertyOf = w 
End Function 

然後

Dim w As Wedge 
For a = 1 To 4 
    w = myWedge(x, a) 
    For c = 1 To 35 
    p = PropertyOf(w, c) 
    If p > 0 Then 
     ' Do your stuff here 
    End If 
    Next c 
Next i 
+0

伊,感謝您的解決方案,只需用W =掙扎myWedge(x,a)什麼是「X」 – Fabby

+0

我只是從您的示例YGBL(x,a)中複製....所以在這種情況下,您可以ma關於x = 1到99的另一個外部循環.... –