单选题 设在工程文件中有一个标准模块,其中定义了如下记录类型:
Type Books
  Name As String * 10
  TelNum As String * 20
End Type
在窗体上画一个名为Command1的命令按钮,要求当执行事件过程Command1_Click时,在顺序文件Person.txt中写入一条记录。下列能够完成该操作的事件过程是______。
  • A.Private Sub Command1_Click() Dim B As Books Open "c:/Person.txt" For Output As #1 B.Name=InputBox("输入姓名") B.TelNum=InputBox("输入电话号码") Write #1,B.Name, B.TelNum Close #1 End Sub B.Private Sub Command1_Click() Dim B As Books Open "c:/Person.txt" For Input As #1 B.Name=InputBox("输入姓名") B.TelNum=InputBox("输入电话号码") Print #1, B.Name, B.TelNum Close #1 End Sub C.Private Sub Command1_Click() Dim B As Books Open "c:/Person.txt" For Output As #1
  • B.Name=InputBox("输入姓名")
  • B.TelNum=InputBox("输入电话号码") Write #1, B Close #1 End Sub
  • D.Private Sub Command1_Click() Open "c:/Person.txt" For Input As #1 Name=InputBox("输入姓名") TelNum=InputBox("输入电话号码") Print #1, Name, TelNum Close #1 End Sub
【正确答案】 A
【答案解析】[解析] 数据文件的写操作分为3步,即打开文件、写入文件和关闭文件。首先,在顺序文件中打开文件写入数据的打开方式为:Open文件名For Output As #文件号。因此B、C选项排除,只看A、D选项。写入顺序文件Print #语句格式为:Print #文件号,变量名,变量名…,Write语句的的格式与Print语句一样:Write #文件号,变量名,变量名。而记录类型变量不能整体引用,需要指明记录变量中的成员名,格式为:记录变量名、成员名,Books类型变量B成员Name和TelNum赋值和引用应该是B.Name、B.TelNum,因此A选项正确。