以下是引用lvguidong123在2012-11-10 08:48:19的发言:
我是想让它每出一个波峰或波谷记一次数,不是要计它的总数。
其实我不大懂,只是从代码来分析。所以你是要即时计算?
那就不能用FOR循环,要改用DO While...Loop循环,外加一个bool值去终止撷取,
因为你定了2...749,感觉是事后计算总数,既然波峰波谷是固定值,
频率也是固定值,那次数不就也是固定值,就只是看你要撷取的范围?
直觉猜想到代码应该会长这样,
你自己再去把这和你的波形图关连起来...
程序代码:
Dim t As Integer
Dim nStop As Boolean
Private Sub Command1_Click()
nStop = False
Do While (nStop = False)
Call AAA(nStop)
Loop
End Sub
Private Sub AAA(nStop As Boolean)
If (t Mod 2 = 0) And (t > 1) Then
If (py(t) = 波峰或波谷) Then
Text1.Text = CStr(Val(Text1.Text) + 1)
End If
End If
DoEvents
t = IIf(t < 750, t + 2, 0)'t范围你自定
Debug.Print t
End Sub
Private Function py(X As Integer) As Integer
'.....
End Function
Private Sub Command2_Click()
nStop = True
End Sub
Private Sub Command3_Click()
t = 0: Text1.Text = CStr(t)
End Sub
Private Sub Form_Load()
t = 0
Command1.Caption = "Start"
Command2.Caption = "Stop"
Command3.Caption = "Clear"
Text1.Text = CStr(t)
End Sub