函数内多个值返回给函数名问题
本帖最后由 hd1439 于 2012-11-06 10:43:39 编辑
Function ReadExcelResult(RowCount)
For i = 1 To RowCount - 1
ResultValue = oWorkBook.Worksheets("TCases").Cells(i+1,8)
If ResultValue = "Pass" Then
iPass = iPass + 1
ElseIf ResultValue = "Not Yet Executed" Then
iNotYetExecuted = iNotYetExecuted + 1
Else
iFail = iFail + 1
Next
End Function
Option Explicit
Private Type RER
iPass As Long
iNotYetExecuted As Long
iFail As Long
End Type
Private Function ReadExcelResult(RowCount, InRER As RER) As RER
Dim i As Long
For i = 1 To RowCount - 1
ResultValue = oWorkBook.Worksheets("TCases").Cells(i + 1, 8)
If ResultValue = "Pass" Then
ReadExcelResult.iPass = InRER.iPass + 1
ElseIf ResultValue = "Not Yet Executed" Then
ReadExcelResult.iNotYetExecuted = InRER.iNotYetExecuted + 1
Else
ReadExcelResult.iFail = InRER.iFail + 1
End If
Next
End Function
Private Sub Command1_Click()
Dim s As RER
s.iPass = 1
s.iNotYetExecuted = 2
s.iFail = 3
s = ReadExcelResult(5, s)
End Sub
[其他解释]
可以返回一个结构体,或者数组。
[其他解释]