作为程序员,我们在设计软件编写代码时最重要的一点为代码量的大小和巧用思维。我在编写学生上机状态查看这个窗体时遇见两个比较棘手的问题:使全部学生下机和选择学生下机,这两个功能的实现甚是煞费脑筋,不过最终采用了三点将这两个功能实现出出来。
但是是哪三个关键点呢?第一:调用MDI窗体的下机按钮,省去大量连接数据库表和计算消费余额的代码
第二:采用数组,使选择下机的数据行能够连续排列
第三:定义tmpselect的运用
Dim tmpselect As Boolean
Private Sub msflexgrid1_mouseup(button As Integer, shift As Integer, x As Single, y As Single)
tmpselect = True
End Sub
Rem:所有学生下线
Private Sub allstudentoutline_Click()
Dim txtsqlonline As String
Dim msgtextonline As String
Dim mrconline As ADODB.Recordset
Dim i As Integer
txtsqlonline = "select * from online_info"
Set mrconline = executesql(txtsqlonline, msgtextonline)
If MSFlexGrid1.Text = "" Then
MsgBox "请先显示数据!", vbOKOnly + vbInformation, "温馨提示"
Else
If mrconline.EOF = False Then
For i = 1 To MSFlexGrid1.Rows - 1
frmMDI.txtcardno.Text = MSFlexGrid1.TextMatrix(i, 0)
frmMDI.cmdclose.Value = True
Next
MsgBox "所有学生均已下机!", vbOKOnly + vbInformation, "温馨提示"
MSFlexGrid1.Clear
End If
End If
End Sub
Private Sub msflexgrid1_click()
If tmpselect = True Then
MSFlexGrid1.TextMatrix(MSFlexGrid1.RowSel, 10) = "√"
End If
End Sub
Private Sub MSFlexGrid1_DblClick()
MSFlexGrid1.TextMatrix(MSFlexGrid1.RowSel, 10) = ""
End Sub
Rem:选择学生下线
Private Sub optionstudentoutline_Click()
Dim a(9999) As String
Dim i As Integer
Dim j As Integer
If MSFlexGrid1.Text = "" Then
MsgBox "请先显示数据!", vbOKOnly + vbInformation, "温馨提示"
Exit Sub
Else
If MSFlexGrid1.RowSel = 0 Then
MsgBox "请先选择数据!", vbOKOnly + vbInformation, "温馨提示"
End If
With MSFlexGrid1
For i = 1 To .Rows - 1
j = 0
If j > .Row Then
Exit Sub
End If
If .TextMatrix(i, 10) = "√" Then
a(j) = i
frmMDI.txtcardno.Text = MSFlexGrid1.TextMatrix(i, 0)
frmMDI.cmdclose.Value = True
Else
MsgBox "请先勾选数据!", vbOKOnly + vbInformation, "温馨提示"
Exit Sub
End If
Next
End With
MsgBox "所选择的学生均已下机!", vbOKOnly + vbInformation, "温馨提示"
End If
End Sub
数组思维的运用是建立在李光小师傅和闫伟强的分享的博客的基础上的,如果没有这两篇博客,或许我会消耗些较为更多的时间。