当前位置:首页 » VB程序题 » 正文

VB程序题:将教材例8.4用随机文件实现。(实验H 数据文件) Visual Basic程序设计教程(第3版) (龚沛曾等编)课后实验源码

VB程序题:将教材例8.4用随机文件实现。(实验H 数据文件) Visual Basic程序设计教程(第3版) (龚沛曾等编) 课后实验源码

解题,代码如下: 

Private Type studtype
    no As String * 6
    name As String * 6
    Mark As Integer
End Type

Dim std As studtype
Dim record As Integer

Private Sub Command1_Click()
    With std
        .no = Val(Text1.Text)
        .name = Text2.Text
        .Mark = Val(Text3.Text)
    End With

    Open "C:\score2" For Random As #1 Len = Len(std)
    record = LOF(1) / Len(std) + 1
    Put #1, record, std
    Close #1
    Text1.Text = ""
    Text2.Text = ""
    Text3.Text = ""
    Text1.SetFocus
End Sub

Private Sub Command2_Click()
    Dim sum, count As Integer
    Open "C:\score2" For Random As #1 Len = Len(std)
    For i = 1 To record
        Get #1, i, std
        sum = sum + std.Mark
        count = count + 1
        List1.AddItem std.no & "  " & std.name & std.Mark
    Next i
    List1.AddItem "总分" & sum
    List1.AddItem "平均成绩" & sum / count
    Close #1
  End Sub

运行程序,效果图如下:


Visual Basic程序设计教程(第3版) (龚沛曾等编)课后实验源码

来源:济亨网

本文链接:http://wb86.com/post/112.html

    << 上一篇 下一篇 >>

    湘公网安备 43011102000514号 - 湘ICP备08100508号