在窗体上画2个文本框(名称分别为Text1和Text2),一个命令按钮(名称为Command1)。并定义以下记录类型和变量: Private Type Teacher ID As Integer Name As String * 10 En

admin2015-09-23  38

问题 在窗体上画2个文本框(名称分别为Text1和Text2),一个命令按钮(名称为Command1)。并定义以下记录类型和变量:
Private Type Teacher
    ID As Integer
    Name As String * 10
End Type
Dim Teach As Teacher
程序运行后,在Text1中输入编号(ID),在Text2中输入姓名(Name),然后单击命令按钮,则把两个文本框中的内容写入随机文件d:\f1.txt。以下能够正确实现上述功能的事件过程是

选项 A、Private Sub Command1_Click()
Open "d:\f1.txt" For Random As #1 Len = Len(Teach)
Teach.ID = Val(Text1.Text)
Teach.Name = Text2.Text
Put #1, 1, Teach
Close #1
End Sub
B、Private Sub Command1_Click()
Open "d:\f1.txt" For Random As #1 Len = Len(Teach)
Teach.ID = Val(Text1.Text)
Teach.Name = Text2.Text
Put #1, Teach.ID, Teach.Name
Close #1
End Sub
C、Private Sub Command1_Click()
Open "d:\f1.txt" For Random As #1 Len = Len(Teach)
Teach.ID = Val(Text1.Text)
Teach.Name = Text2.Text
Write #1, 1, Teach
Close #1
End Sub
D、Private Sub Command1_Click()
Open "d:\f1.txt" For Random As #1 Len = Len(Teach)
Teach.ID = Val(Text1.Text)
Teach.Name = Text2.Text
Write #1, Teach.ID, Teach.Name
Close #1
End Sub

答案A

解析 向顺序文件写操作格式:Write#文件号,表达式,题目要求为随机文件,故选项C和D均错误;向随机文件写操作格式:Put #文件名,[记录号],变量,选项B是将Text2中输入姓名写入到随机文件中,而不是将两个文本框的内容写入,故选项B错误。本题正确答案为A。
转载请注明原文地址:https://kaotiyun.com/show/7GLp777K
0

最新回复(0)