五笔打字通主页
VB程序题:编写如图H.1所示的应用程度。若单击“建立文件”按钮,则分别用Print#和和Write#语句将三个同学的学号、姓名和成绩写入Score.dat和Score1.dat;若单击“读取文件”按钮,则用line Input 语句按行将两个(当前目录)文件中的数据显示在相应的文本框。
其中:学号和姓名是字符串类型,成绩是整型。
图H.1
解题,画2个按钮,2个文本框(2个文本框的 MultiLine 属性设置为 True),代码如下:
Private Sub Command1_Click()
Open "c:\score" For Output As #1
Print #1, "051023", "王海涛", 66
Print #1, "052498", "周文英", 88
Print #1, "050992", "陈建东", 77
Open "c:\score1" For Output As #2
Write #2, "051023", "王海涛", 66
Write #2, "052498", "周文英", 88
Write #2, "050992", "陈建东", 77
Close
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Dim no As String, name As String, s As Integer
Open "c:\score" For Input As #1
Do While Not EOF(1)
Line Input #1, linedata
Text1.Text = Text1.Text & linedata & Chr(13) & Chr(10)
Loop
Open "c:\score1" For Input As #2
Do While Not EOF(2)
Line Input #2, linedata
Text2.Text = Text2.Text & linedata & Chr(13) & Chr(10)
Loop
Close
End Sub
Visual Basic程序设计教程(第3版) (龚沛曾等编)课后实验源码
来源:济亨网
本文链接:http://wb86.com/post/107.html