其实我不太知道机房怎么优化,感觉优化就是减少bug的出现。下面我来说一下我做机房的时候避免bug出现的一些简单操作。大神多多指点:
1、比较基础的,登陆名或者其他窗体只能输入数字
Private Sub txtUserName_KeyPress(KeyAscii As Integer)
If (KeyAscii >= 48 And KeyAscii <= 57) Or KeyAscii = 8 Then
Else
KeyAscii = 0
End If
End Sub
2、combox文本框只能进行选择,不能进行输入
Private Sub Combo1_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub
3、组合查询当中日期和时间的输入限制提示框
Private Sub Combo1_click()
If Combo1.Text = "上机日期" Or Combo1.Text = "上机时间" Or Combo1.Text = "下机时间" Or Combo1.Text = "下机日期" Then
MsgBox "日期请输入 yyyy-mm-d格式,时间请输入 hh:mm:ss格式", , "提示"
Exit Sub
End If
End Sub
4、组合查询当中日期和时间限制其他特殊符号
Private Sub text1_KeyPress(KeyAscii As Integer)
If Combo2.Text = "上机日期" Or Combo2.Text = "下机日期" Then
If (KeyAscii >= 48 And KeyAscii <= 57) Or KeyAscii = 8 Or KeyAscii = 47 Then
Else
KeyAscii = 0
End If
End If
If Combo2.Text = "下机时间" Or Combo2.Text = "上机时间" Then
If (KeyAscii >= 48 And KeyAscii <= 57) Or KeyAscii = 8 Or KeyAscii = 58 Then
Else
KeyAscii = 0
End If
End If
End Sub
5、防止数据库中存在空值而出现错误:
mrc3.Fields(12) = Trim(txtbalance.Text) & ""
6、在结账或者下机当中避免查询不到数据,用IsNull
txtsql = "select sum(addmoney) from recharge_info where userid='" & Trim(Combo1.Text) & "' and status='未结账'"
Set mrc2 = ExecuteSQL(txtsql, msgtext)
If IsNull(mrc2.Fields(0)) Then
txtaddcash.Text = 0
7、在下机当中,使当msf表当中存在多条数据的时候,使line表同步全部数据:
With MSFlexGrid1
For i = 1 To MSFlexGrid1.Rows - 1
txtsql = "select * from online_info where cardno='" & Trim(.TextMatrix(i, 0)) & "'"
Set mrc1 = ExecuteSQL(txtsql, msgtext)
Next i
End With
暂时先这么多~