第一,数据库单一开启关闭原则。
经验:我进行33次数据库操作,每次开启关闭数据库,结果让程序运行起来好慢。
解决方法:同意SUB里:只允许有一对:
Dim myconnection As New OleDbConnection(PubDB)
Dim mycommand As OleDbCommand
myconnection.Open()
。。。。。。。。。。。
myconnection.Close()
第二,统一改变----信号原则
同一种功能在N次调用,会容易出错。
解决方法: 利用信号戳发,同一功能只用一次,其他都用信号戳发,增加代码的复用性。
Private Sub TrackBar1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackBar1.LostFocus
NumericUpDown4.Value = TrackBar1.Value / 2.55
End Sub
Private Sub TrackBar1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TrackBar1.MouseDown
PubVi = 1
End Sub
Private Sub TrackBar1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TrackBar1.MouseUp
PubVi = 0
End Sub
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
NumericUpDown4.Value = TrackBar1.Value / 2.55
End Sub
Private Sub NumericUpDown4_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles NumericUpDown4.GotFocus
NumericUpDown4.Select(0, NumericUpDown4.Value.ToString().Length)
TrackBar1.Value = NumericUpDown4.Value * 2.55
PubVi = 1
End Sub
Private Sub NumericUpDown4_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles NumericUpDown4.LostFocus
TrackBar1.Value = NumericUpDown4.Value * 2.55
PubVi = 0
End Sub
Private Sub NumericUpDown4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles NumericUpDown4.KeyPress
If e.KeyChar = ChrW(13) Then
TrackBar1.Value = NumericUpDown4.Value * 2.55
End If
End Sub
Private Sub NumericUpDown4_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown4.ValueChanged
TrackBar1.Value = NumericUpDown4.Value * 2.55
End Sub
Private Sub NumericUpDown4_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles NumericUpDown4.KeyDown
TrackBar1.Value = NumericUpDown4.Value * 2.55
PubVi = 1
End Sub
Private Sub NumericUpDown4_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles NumericUpDown4.KeyUp
TrackBar1.Value = NumericUpDown4.Value * 2.55
PubVi = 0
End Sub
Private Sub TrackBar1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackBar1.ValueChanged
If PubVi = 1 Then
Label72.BackColor = Color.FromArgb(TrackBar1.Value, Val(NumericUpDown1.Value), Val(NumericUpDown2.Value), Val(NumericUpDown3.Value))
End If
End Sub