要求:可以新建或打开一个班级的成绩,各班所开设的课程和学生名册可以任意设定,成绩可以随时录入、修改和保存,数据以文件形式保存,可以计算每个学生的总分、均分和全班各门课程的平均分(用VB6编写)
非常感谢。。。。。。
花了一下午 终于弄出来!你给我你的邮箱,我把工程打包发给你,我做得和乱,你还要该该!你上面的要求是实现了
Private Sub Form_Load() '初始化开的课程,在这里所有的班级都开设了这九门课程!
Combo1.AddItem "数学"
Combo1.AddItem "语文"
Combo1.AddItem "英语"
Combo1.AddItem "生物"
Combo1.AddItem "化学"
Combo1.AddItem "物理"
Combo1.AddItem "政治"
Combo1.AddItem "历史"
Combo1.AddItem "地理"
End Sub
'这里是datalist控件 与 adodc1绑定,在列表框中显示 学生姓名
Private Sub DataList1_Click()
Text1.Text = DataList1.BoundText' 用与显示学生所在班级
Text4.Text = DataList1.Text '这个是测试用的,可以删去,不过下面有关代码就要换一下!
End Sub
'在这里执行的是修改
Private Sub command4_Click()
Dim a As Single
Dim b As Integer
Dim c As String
if combo1.text="" then exit sub
Adodc1.Refresh
Adodc1.Recordset.Find ("studentname like '" & Text4.Text & "' ") '查找学生信息
If Adodc1.Recordset.EOF Or Adodc1.Recordset.BOF Then'查找失败
MsgBox "123"
Else
'要找的学生对应科目的成绩
If Combo1.Text = "数学" Then
Adodc1.Recordset("数学成绩") = Text3.Text
Adodc1.Recordset.Update
End If
If Combo1.Text = "语文" Then
Adodc1.Recordset("语文成绩") = Text3.Text
Adodc1.Recordset.Update
End If
If Combo1.Text = "英语" Then
Adodc1.Recordset("英语成绩") = Text3.Text
Adodc1.Recordset.Update
End If
If Combo1.Text = "生物" Then
Adodc1.Recordset("生物成绩") = Text3.Text
Adodc1.Recordset.Update
End If
If Combo1.Text = "化学" Then
Adodc1.Recordset("化学成绩") = Text3.Text
Adodc1.Recordset.Update
End If
If Combo1.Text = "物理" Then
Adodc1.Recordset("物理成绩") = Text3.Text
Adodc1.Recordset.Update
End If
If Combo1.Text = "政治" Then
Adodc1.Recordset("政治成绩") = Text3.Text
Adodc1.Recordset.Update
End If
If Combo1.Text = "历史" Then
Adodc1.Recordset("历史成绩") = Text3.Text
Adodc1.Recordset.Update
End If
If Combo1.Text = "地理" Then
Adodc1.Recordset("地理成绩") = Text3.Text
Adodc1.Recordset.Update
End If
Adodc1.Recordset("学生总分") = Val(Adodc1.Recordset("数学成绩")) + Val(Adodc1.Recordset("语文成绩")) + Val(Adodc1.Recordset("英语成绩")) + Val(Adodc1.Recordset("化学成绩")) + Val(Adodc1.Recordset("生物成绩")) + Val(Adodc1.Recordset("物理成绩")) + Val(Adodc1.Recordset("政治成绩")) + Val(Adodc1.Recordset("历史成绩")) + Val(Adodc1.Recordset("地理成绩"))
'控制保存结果,保留两位小数
a = CSng(Val(Adodc1.Recordset("学生总分")) / 9)
b = InStr(Trim(Str(a)), ".")
If b <> 0 Then
If Val(Mid(Str(a), b + 3, 1)) >= 5 Then'若小数点后三位不小于5 则+0.01
c = Str(Val(Mid(Trim(Str(a)), 1, b + 2)) + 0.01)
Else
c = Str(Val(Mid(Trim(Str(a)), 1, b + 2)))
End If
Adodc1.Recordset("学生平均分") = Trim(c)
Else
Adodc1.Recordset("学生平均分") = Trim(Str(a) & ".00")
End If
Adodc1.Recordset.Update
MsgBox "修改完毕!"
End Sub
'这部分是提供查询学生成绩的,不过只能查对应课程的成绩
Private Sub Command2_Click()
If Combo1.Text = "" Then
MsgBox "请选课程名!"
Exit Sub
End If
Adodc1.Refresh
Adodc1.Recordset.Find ("studentname like '" & Text4.Text & "' ")
If Adodc1.Recordset.EOF Or Adodc1.Recordset.BOF Then
MsgBox "123"
Else
If Combo1.Text = "数学" Then
Text3.Text = Adodc1.Recordset("数学成绩")
End If
If Combo1.Text = "语文" Then
Text3.Text = Adodc1.Recordset("语文成绩")
End If
If Combo1.Text = "英语" Then
Text3.Text = Adodc1.Recordset("英语成绩")
End If
If Combo1.Text = "生物" Then
Text3.Text = Adodc1.Recordset("生物成绩")
End If
If Combo1.Text = "化学" Then
Text3.Text = Adodc1.Recordset("化学成绩")
End If
If Combo1.Text = "物理" Then
Text3.Text = Adodc1.Recordset("物理成绩")
End If
If Combo1.Text = "政治" Then
Text3.Text = Adodc1.Recordset("政治成绩")
End If
If Combo1.Text = "历史" Then
Text3.Text = Adodc1.Recordset("历史成绩")
End If
If Combo1.Text = "地理" Then
Text3.Text = Adodc1.Recordset("地理成绩")
End If
End If
End Sub
,这是提供录入的部分,其实跟修改没什么两样,仔细看看有什么不同吧!
Private Sub Command1_Click()
Dim a As Single
Dim b As Integer
Dim c As String
If Combo1.Text = "" Then
MsgBox "请选课程名!"
Exit Sub
End If
Adodc1.Refresh
Adodc1.Recordset.Find ("studentname like '" & Text4.Text & "' ")
If Adodc1.Recordset.EOF Or Adodc1.Recordset.BOF Then
MsgBox "123"
Else
If Combo1.Text = "数学" Then
Adodc1.Recordset("数学成绩") = Text2.Text
Adodc1.Recordset.Update
End If
If Combo1.Text = "语文" Then
Adodc1.Recordset("语文成绩") = Text2.Text
Adodc1.Recordset.Update
End If
If Combo1.Text = "英语" Then
Adodc1.Recordset("英语成绩") = Text2.Text
Adodc1.Recordset.Update
End If
If Combo1.Text = "生物" Then
Adodc1.Recordset("生物成绩") = Text2.Text
Adodc1.Recordset.Update
End If
If Combo1.Text = "化学" Then
Adodc1.Recordset("化学成绩") = Text2.Text
Adodc1.Recordset.Update
End If
If Combo1.Text = "物理" Then
Adodc1.Recordset("物理成绩") = Text2.Text
Adodc1.Recordset.Update
End If
If Combo1.Text = "政治" Then
Adodc1.Recordset("政治成绩") = Text2.Text
Adodc1.Recordset.Update
End If
If Combo1.Text = "历史" Then
Adodc1.Recordset("历史成绩") = Text2.Text
Adodc1.Recordset.Update
End If
If Combo1.Text = "地理" Then
Adodc1.Recordset("地理成绩") = Text2.Text
Adodc1.Recordset.Update
End If
Adodc1.Recordset("学生总分") = Val(Adodc1.Recordset("数学成绩")) + Val(Adodc1.Recordset("语文成绩")) + Val(Adodc1.Recordset("英语成绩")) + Val(Adodc1.Recordset("化学成绩")) + Val(Adodc1.Recordset("生物成绩")) + Val(Adodc1.Recordset("物理成绩")) + Val(Adodc1.Recordset("政治成绩")) + Val(Adodc1.Recordset("历史成绩")) + Val(Adodc1.Recordset("地理成绩"))
a = CSng(Val(Adodc1.Recordset("学生总分")) / 9)
b = InStr(Trim(Str(a)), ".")
If b <> 0 Then
If Val(Mid(Str(a), b + 3, 1)) >= 5 Then
c = Str(Val(Mid(Trim(Str(a)), 1, b + 2)) + 0.01)
Else
c = Str(Val(Mid(Trim(Str(a)), 1, b + 2)))
End If
Adodc1.Recordset("学生平均分") = Trim(c)
Else
Adodc1.Recordset("学生平均分") = Trim(Str(a) & ".00")
End If
Adodc1.Recordset.Update
MsgBox "录入完毕!"
End If
End Sub
'这部分执行全班同学各科的平均分
Private Sub Command3_Click()
Dim i As Integer
Dim a(1 To 9) As Single
Dim b(1 To 9) As String
Adodc1.Refresh
Adodc1.Recordset.Find (" class like '" & Text1.Text & "' ")找班级相同的人,
If Adodc1.Recordset.EOF Or Adodc1.Recordset.BOF Then
MsgBox "123"
Else
For i = 1 To 9
a(i) = Val(DataGrid1.Columns(DataGrid1.Col + i + 1))
Next i
j = 1
s1:
Adodc1.Recordset.MoveNext '看还有没有相同的
Adodc1.Recordset.Find (" class like '" & Text1.Text & "' ")'找班级相同的人,
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveLast
For i = 1 To 9
a(i) = a(i) / j'控制输入结果为 保留两位小数!
d = InStr(Trim(Str(a(i))), ".")
If d <> 0 Then
If Val(Mid(Str(a(i)), d + 3, 1)) >= 5 Then
b(i) = Str(Val(Mid(Trim(Str(a(i))), 1, d + 2)) + 0.01)
Else
b(i) = Str(Val(Mid(Trim(Str(a(i))), 1, d + 2)))
End If
Else
b(i) = Str(a(i)) & ".00"
End If
Next i
Adodc2.Recordset("数学平均成绩") = b(1)
Adodc2.Recordset("语文平均成绩") = b(2)
Adodc2.Recordset("英语平均成绩") = b(3)
Adodc2.Recordset("化学平均成绩") = b(4)
Adodc2.Recordset("生物平均成绩") = b(5)
Adodc2.Recordset("物理平均成绩") = b(6)
Adodc2.Recordset("政治平均成绩") = b(7)
Adodc2.Recordset("历史平均成绩") = b(8)
Adodc2.Recordset("地理平均成绩") = b(9)
Adodc2.Recordset.Update
Exit Sub
Else
For i = 1 To 9
a(i) = a(i) + Val(DataGrid1.Columns(DataGrid1.Col + i + 1))
Next i
j = j + 1
GoTo s1
End If
End If
End Sub
最后本工程设置了2个adodc控件 其visible属性为false 2个datagrid 控件 几个标签,几个命令按钮,几个text
数据库建了两张表,一个张的字段分别是 班级,学生姓名,数学成绩........地理成绩,学生总分,学生平均分.表二 班级,数学平均成绩....地理平均成绩
adodc1关联表一adodc2关联表二
上面的程序 刚刚做完,还没完善,也么经过多少的测试,还有一导出的功能 我还没写,那功能也容易实现!你先看看吧!