vb.net - 从模块返回值
问题描述
我似乎无法在例程结束时返回计数器值。
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
解决方案
为了娱乐:
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
推荐阅读
- php - PHP 从 MS Access MDB 收集数据时出现意外结果
- python - How to match from a word up to the end of a sentence?
- typescript - Need a boolean result by finding whether 2 elements are present in an array or not
- php - MissingAuthenticationTokenException ("Missing Authentication Token") from CognitoIdentityProviderClient::adminCreateUser()
- matlab - 如何使用 simulink 将向量或矩阵输出到工作区?
- c# - DOTNET Core - 为会话保留数据库名称
- react-native - 如何在 React Native 中引用启动图像
- javascript - Link to Scroll, TypeError: this.props.parentMethod is not a function
- java - 文件名未显示在 FileDialog 中
- python - 如何在 django html 中制作详细视图?