Private Sub Command1_Click()
If CBool(SheepCount(priFold())) Then '如果羊圈里还有羊的话
Text2.Text = SheepNabByFold(priFold()) '羊圈存栏数量
Text1.Text = SheepCount(priFold()) '被抓住的小羊羔编号
For tIndex = 0 To SheepCount(priFold()) - 1 '显示羊圈里的小羊。
Text1.Text = Text1.Text & " " & priFold(tIndex)
Next
Else
Text1.Text = "没有羊了!你还乱抓什么?"
End If
End Sub
Private Sub Form_Load()
Randomize Timer
ReDim priFold(100)
For tIndex = 0 To 100
priFold(tIndex) = tIndex
Next
End Sub
Function SheepCount(ByRef pFold() As Long) As Long
Dim tOutCount As Long
Dim tSheepIndex_Start As Long
Dim tSheepIndex_End As Long
Dim tSheepIndex_Rnd As Long
Err.Clear
On Error Resume Next
tSheepIndex_End = UBound(pFold): tSheepIndex_Start = LBound(pFold)
If Not CBool(Err.Number) Then
tOutCount = Abs(tSheepIndex_End - tSheepIndex_Start) + 1
End If
SheepCount = tOutCount
End Function
Function SheepNabByFold(ByRef pFold() As Long) As Long
Dim tOutSheep As Long
Dim tSheepIndex As Long
Dim tSheepCount As Long
Dim tSheepIndex_Start As Long
Dim tSheepIndex_End As Long
Dim tSheepIndex_Rnd As Long
Dim tFoldSpace() As Long