设在工程中有一个标准模块,其中定义了如下记录类型: Type Books Name As String * 10 TelNum As String * 20 EndType 在窗体中添加一个名为Commandl的命令按钮,要求

admin2010-03-30  26

问题 设在工程中有一个标准模块,其中定义了如下记录类型:    Type Books    Name As String * 10    TelNum As String * 20    EndType    在窗体中添加一个名为Commandl的命令按钮,要求单击命令按钮时,在顺序文件 Ptxt中写入一条记录。下列能够完成该操作的程序段是    (    )

选项 A、Private Sub Commandl_Click()   Dim B As Books   Open"d:\P1.txt"For Output As   #1   B. Name=InputBox( "姓名")   B. TelNum=InputBox("电话号码")   Write #1,B. Name,B. TelNum   Close #1   EndSub
B、Private Sub Commandl_Click()   Dim B As Books   Open" d:\Pl.txt" For Input As   B. Name=InputBox ("姓名")   B. TelNum=InputBox ("电话号码")   Print #1,B. Name,B. TelNum   Close #1   EndSub
C、Private Sub Commandl_Click()   Dim B As Books   Open"d:\P1. txt"For Output As   B. Name=InputBox("姓名")   B. TelNum=InputBox ("电话号码")   Write #1,B   Close #1   EndSub
D、Private Sub Commandl Cliek()  Open"d:\P1.txt" For Input As   Name=InputBox("姓名")   TelNum=InputBox ("电话号码")   Print #1,Name,TelNum   Close #1   EndSub

答案1

解析 建立并打开一个新的数据文件的打开方式为Output,故可排除选项B、D项。顺序文件的写操作可以使用Print#或 Write#语句。格式为:
   Print#文件号,表达式表
   Write#文件号,表达式表
   题中B是一个Books变量,这个变量包括两个成员,在进行写入操作时,不能笼统的写成Write#1,B排除选项C,只有选项A是正确的。
转载请注明原文地址:https://kaotiyun.com/show/w1mp777K
0

最新回复(0)