问题慢慢抓:
1:
If Trim(Combo1.Text) = "" Then
MsgBox "请选择学院!", vbInformation + vbOKOnly, "系统提示信息"
Exit Sub
End If
If Trim(Combo2.Text) = "" Then
MsgBox "请选择专业!", vbInformation + vbOKOnly, "系统提示信息"
Exit Sub
End If
If Trim(Combo3.Text) = "" Then
MsgBox "请选择班级!", vbInformation + vbOKOnly, "系统提示信息"
Exit Sub
End If
改成:
IF TRIM(COMBO1.TEXT & COMBO2.TEXT & COMBO3.TEXT)="" THEN...
2:
使用控件数组,不要用单个的控件,这么多控件名字很容易搞错,要是想写一个统一的事件代码还要用FOR EACH,太麻烦。
控件数组很简单,选中一个控件,按“CTRL + C" 再点窗体,按”CTRL + V"就会问你是否哟昂创建控件数组了。
然后你就可以用型如:
FOR I =0 TO LABEL1.COUNT -1
LABEL1(I).ENABLE = TRUE
NEXT
这样简洁的代码了
并且触发事件也变成了:
SUB COMMAMD1_CLICK(INDEX AS INTEGER)
SELECT CASE INDEX
CASE 0: '写第一个按钮按下后要做的动作
CASE 1: '写第二个按钮按下后要做的动作END SELECT
...
END SELECT
END SUB
又简单了很多
Private Sub Command1_Click()
If Trim(Combo1.Text) = "" Then
MsgBox "请选择学院!", vbInformation + vbOKOnly, "系统提示信息"
Exit Sub
End If
If Trim(Combo2.Text) = "" Then
MsgBox "请选择专业!", vbInformation + vbOKOnly, "系统提示信息"
Exit Sub
End If
If Trim(Combo3.Text) = "" Then
MsgBox "请选择班级!", vbInformation + vbOKOnly, "系统提示信息"
Exit Sub
End If
'绑定学生信息
Dim i As Integer
Dim SqlStr As String
SqlStr = "select * from pdfzsz where 学号 in(select distinct 学号 from xsdjb where"
SqlStr = SqlStr & Xueyuan & Zhuanye & Banji & ") order by 学号"
If Adodc5.Recordset.RecordCount = 0 Then
'添加pdfzsz中的记录
SqlStr = "select * from xsdjb where 学号 in(select distinct 学号 from xsdjb where"
SqlStr = SqlStr & Xueyuan & Zhuanye & Banji & ") order by 学号"
If Adodc6.Recordset.RecordCount = 0 Then
MsgBox "没有查找到满足条件的记录!", vbInformation + vbOKOnly
MSHFlexGrid1.Clear
Call BTop
Exit Sub
End If
Adodc6.Recordset.MoveFirst
For i = 1 To Adodc6.Recordset.RecordCount
Adodc5.Recordset.AddNew
Adodc5.Recordset.Fields("学号") = Adodc6.Recordset.Fields("学号")
Adodc5.Recordset.Fields("姓名") = Adodc6.Recordset.Fields("姓名")
Adodc5.Recordset.Fields("学院") = Adodc6.Recordset.Fields("学院")
Adodc5.Recordset.Fields("专业") = Adodc6.Recordset.Fields("专业")
Adodc5.Recordset.Fields("班级") = Adodc6.Recordset.Fields("班级")
Adodc5.Recordset.Update
Adodc6.Recordset.MoveNext
Next i
SqlStr = "select * from pdfzsz where 学号 in(select distinct 学号 from xsdjb where"
SqlStr = SqlStr & Xueyuan & Zhuanye & Banji & ") order by 学号"
Adodc5.RecordSource = SqlStr
Adodc5.Refresh
Else
'修改xsdjb中的记录
SqlStr = "select * from xsdjb where 学号 in(select distinct 学号 from xsdjb where"
SqlStr = SqlStr & Xueyuan & Zhuanye & Banji & ") order by 学号"
Adodc5.Recordset.MoveFirst
Adodc7.Recordset.MoveFirst
For i = 1 To Adodc7.Recordset.RecordCount
If Adodc5.Recordset.EOF = False Then
If Adodc5.Recordset.Fields("学号") = Adodc7.Recordset.Fields("学号") Then
Adodc5.Recordset.MoveNext
Adodc7.Recordset.MoveNext
Else
Adodc5.Recordset.AddNew
Adodc5.Recordset.Fields("学号") = Adodc7.Recordset.Fields("学号")
Adodc5.Recordset.Fields("姓名") = Adodc7.Recordset.Fields("姓名")
Adodc5.Recordset.Fields("学院") = Adodc7.Recordset.Fields("学院")
Adodc5.Recordset.Fields("专业") = Adodc7.Recordset.Fields("专业")
Adodc5.Recordset.Fields("班级") = Adodc7.Recordset.Fields("班级")
Adodc5.Recordset.Update
Adodc7.Recordset.MoveNext
End If
Else
Adodc5.Recordset.AddNew
Adodc5.Recordset.Fields("学号") = Adodc7.Recordset.Fields("学号")
Adodc5.Recordset.Fields("姓名") = Adodc7.Recordset.Fields("姓名")
Adodc5.Recordset.Fields("学院") = Adodc7.Recordset.Fields("学院")
Adodc5.Recordset.Fields("专业") = Adodc7.Recordset.Fields("专业")
Adodc5.Recordset.Fields("班级") = Adodc7.Recordset.Fields("班级")
Adodc5.Recordset.Update
Adodc7.Recordset.MoveNext
End If
Next
Adodc5.Refresh
End If
'定性_学生干部
SqlStr = "select * from S_dingxing where 学号 in(select distinct 学号 from pdfzsz where"
SqlStr = SqlStr & Xueyuan & Zhuanye & Banji & ") order by 学号"
Adodc9.ConnectionString = connectstring()
Adodc9.CommandType = adCmdText
Adodc9.RecordSource = SqlStr
Adodc9.Refresh
MSHFlexGrid1.Rows = 2
If Adodc5.Recordset.RecordCount <> 0 Then
For i = 1 To Adodc5.Recordset.RecordCount
MSHFlexGrid1.RowHeight(i) = 300
MSHFlexGrid1.TextMatrix(i, 0) = i
MSHFlexGrid1.TextMatrix(i, 1) = Adodc5.Recordset.Fields("学号")
MSHFlexGrid1.TextMatrix(i, 2) = Adodc5.Recordset.Fields("姓名")
If Adodc9.Recordset.RecordCount = Adodc5.Recordset.RecordCount Then
If Adodc9.Recordset.Fields("学生干部") <> "" Then
MSHFlexGrid1.TextMatrix(i, 3) = Adodc9.Recordset.Fields("学生干部")
Adodc9.Recordset.MoveNext
End If
End If
MSHFlexGrid1.Rows = MSHFlexGrid1.Rows + 1
Adodc5.Recordset.MoveNext
Next i
MSHFlexGrid1.Rows = MSHFlexGrid1.Rows - 1
MSHFlexGrid1.FixedCols = 3
End If
'加载数据
Dim j As Integer
Dim l(12) As String
l(3) = "学生干部"
l(4) = "增减分"
l(5) = "先进个人"
l(6) = "先进个人得分事由"
l(7) = "先进集体"
l(8) = "先进集体得分事由"
l(9) = "精神文明"
l(10) = "精神文明得分事由"
l(11) = "总分"
l(12) = "排名"
Adodc5.Recordset.MoveFirst
For i = 1 To Adodc5.Recordset.RecordCount
For j = 4 To 12
If Adodc5.Recordset.Fields(l(j)) <> "" Then MSHFlexGrid1.TextMatrix(i, j) = Adodc5.Recordset.Fields(l(j))
Next j
Adodc5.Recordset.MoveNext
Next i
InputText.Text = MSHFlexGrid1.Text