电机模拟程序
流程图:
关键代码:
1、在系统单击开始时,让计时器有效。
Private Sub cmdstart_Click()
Call SetTimerEnable
End Sub
设置“计时器”有效函数
Private Sub SetTimerUnenable()
tmVoltage.Interval = Val(txtVoltageInterval.Text)
tmVoltage.Enabled = False
tmCurrent.Interval = Val(txtCurrentInterval.Text)
tmCurrent.Enabled = False
tmSpeed.Interval = Val(txtSpeedInterval.Text)
tmSpeed.Enabled = False
End Sub
2、在系统单击暂停时,让计时器无效。
Private Sub cmdstop_Click()
Call SetTimerUnenable
End Sub设置“计时器”无效函数:
Private Sub SetTimerEnable()
tmVoltage.Interval = Val(txtVoltageInterval.Text)
tmVoltage.Enabled = True
tmCurrent.Interval = Val(txtCurrentInterval.Text)
tmCurrent.Enabled = True
tmSpeed.Interval = Val(txtSpeedInterval.Text)
tmSpeed.Enabled = True
End Sub
3、系统退出时,保存数据到文件。
Private Sub cmdExit_Click()
Call Writetofile
End
Unload Me
End Sub
保存数据到文件的函数。
Private Sub Writetofile()
Open "e:/a1.txt" For Output As #1
Open "e:/a2.txt" For Output As #2
Open "e:/a3.txt" For Output As #3
For i = 0 To lstVoltage.ListCount - 1
Write #1,lstVoltage.List(i)
Next i
For i = 0 To lstCurrent.ListCount - 1
Write #2,lstCurrent.List(i)
Next i
For i = 0 To lstSpeed.ListCount - 1
Write #3,lstSpeed.List(i)
Next i
Close #1
Close #2
Close #3
End Sub
4、每个测试项目对应的函数。
Private Sub tmCurrent_Timer()
'产生模拟电流值
Dim simuCurrent As Single
simuCurrent = 10 * Sqr(2) * Rnd
lblCurrent.Caption = simuCurrent
If simuCurrent > 10 Then
lblisCompensateCurr.Visible = False
lblCurrent.Forecolor = RGB(255,0)
End If
If simuVoltage < 7 Then
compensation = 10 - simuCurrent
simuCurrent = simuCurrent + Int(compensation)
lblCurrent.Caption = Format(simuCurrent,"###.##")
lblisCompensateCurr.Visible = True
lblCurrent.Forecolor = RGB(255,0)
Else
lblisCompensateCurr.Visible = False
lblCurrent.Forecolor = RGB(0,0)
End If
lstCurrent.AddItem Format(simuCurrent,"###.##") & " " & DateTime.Time
End Sub
Private Sub tmSpeed_Timer()
'产生模拟转速值
Dim simuSpeed As Single
simuSpeed = 1000 * Sqr(2) * Rnd
If simuSpeed < 800 Then
simuSpeed = 1000
End If
lblSpeed.Caption = simuSpeed
lstSpeed.AddItem Format(simuSpeed,"###.##") & " " & DateTime.Time
End Sub
Private Sub tmVoltage_Timer()
'产生模拟电压值
Dim simuVoltage As Single
simuVoltage = 220 * Sqr(2) * Rnd
lblVoltage.Caption = simuVoltage
If simuVoltage > 220 Then
lblisCompensation.Visible = False
lblVoltage.Forecolor = RGB(255,0)
End If
If simuVoltage < 200 Then
compensation = 220 - simuVoltage
simuVoltage = simuVoltage + Int(compensation)
lblVoltage.Caption = Format(simuVoltage,"###.##")
lblisCompensation.Visible = True
lblVoltage.Forecolor = RGB(255,0)
Else
lblisCompensation.Visible = False
lblVoltage.Forecolor = RGB(0,0)
End If
lstVoltage.AddItem Format(simuVoltage,"###.##") & " " & DateTime.Time
End Sub
总结以上是内存溢出为你收集整理的VB电机监测模拟程序全部内容,希望文章能够帮你解决VB电机监测模拟程序所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)