首页 > 解决方案 > 从模块返回值

问题描述

我似乎无法在例程结束时返回计数器值。

Sub CountCheckBoxes(sldTemp As Slide)
    Dim counter As Integer
    Dim shpTemp As Shape
    For Each shpTemp In sldTemp.Shapes
        If shpTemp.Type = msoOLEControlObject Then
            If TypeName(shpTemp.OLEFormat.Object) = "CheckBox" Then
                If shpTemp.OLEFormat.Object.Value = True Then
                    counter = counter + 1             
                End If
            End If
        End If
    Next
    Return counter
End Function

编辑新代码:问题是当我输入Return Counter然后按回车时。我有这个功能的原因是计算幻灯片上有多少复选框是真的,然后返回值:

Function CountCheckBoxes(sldTemp As Slide) As Integer
    Dim counter As Integer
    Dim shpTemp As Shape

    For Each shpTemp In sldTemp.Shapes
        If shpTemp.Type = msoOLEControlObject Then
           If TypeName(shpTemp.OLEFormat.Object) = "CheckBox" Then
              If shpTemp.OLEFormat.Object.Value = True Then
                 counter = counter + 1
              End If
           End If
        End If
    Next
    Return counter 
End Function

标签: vb.net

解决方案


为了娱乐:

Function CountCheckBoxes(sldTemp As Slide) As Integer
    Return sldTemp.Shapes.Count(Function(s) s.Type = msoOLEControlObject AndAlso TypeName(s.OLEFormat.Object) = "CheckBox" AndAlso s.OLEFormat.Object.Value)
End Function

推荐阅读