提高程序运行效率的两个原则

第一,数据库单一开启关闭原则。

经验:我进行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


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值