代码之家  ›  专栏  ›  技术社区  ›  nordscan

VB6-使结果编号为序列

  •  0
  • nordscan  · 技术社区  · 8 年前

    你好,我有这个VB6代码

    Public Sub ShowOperations()
    
        Dim Drw As Drawing
        Set Drw = App.ActiveDrawing
    
        Dim Ops As Operations
        Set Ops = Drw.Operations
    
        Dim Op As Operation
        For Each Op In Ops
    
            For Each SubOp In Op.SubOperations
    
                Debug.Print Op.Number & "-" & Op.SubOperations.Count
    
            Next SubOp
        Next Op
    End Sub
    

    在操作中可以有更多的子操作。 但我的结果是这样的

    1-1
    2-2
    2-2
    3-1
    4-3
    4-3
    4-3
    5-1
    

    正如你所看到的操作2,它显示了总共2个子操作……但我需要重新显示

    1-1
    2-1
    2-2
    3-1
    4-1
    4-2
    4-3
    5-1
    

    有人能帮我吗。。。

    非常感谢。

    1 回复  |  直到 8 年前
        1
  •  1
  •   user3598756    8 年前

    只需添加SubOp计数器:

    Dim nSubOp As Long '<--| declare a SubOp counter
    For Each Op In Ops
        nSubOp = 0 '<--| initialize SubOp counter
        For Each SubOp In Op.SubOperations
            nSubOp = nSubOp + 1 '<--| update SubOp counter
            Debug.Print Op.Number & "-" & nSubOp
        Next SubOp
    Next Op