问题 单项选择题

设在工程中有一个标准模块,其中定义了如下记录类型:
TyPe Record
ID A3 Integer
Name As String*20
End TyPe
在窗体中添加一个名为Command1的命令按钮,假设d:\F1.dat文件中含有5个用户自定义类型的记录。要求当执行事件过程Command1_Click时,随机访问该文件,并把文件中的第4条记录读出。下列能够完成该操作的程序段是

A.Private Sub Command1_Click( )
Dim MyRecord As Record,Position
Open"d:\F1.dat"For Random As#1 Len=Len(My Record)
Position=4
Get#1,Position,Myrecord
Close #1
End Sub

B.Private Sub Command1_Click( )
Dim MyRecord As Record,Position
Open"d:\F1.dat"For Random As #1 Len=Len(MyRecord)
Position=4
Put #1,Position,MyRecord
Close#1
End Sub

C.Private Sub Command1_Click( )
Dim MyRecord As Record,Position
Open"d:\F1.dar"For OutPut As #1 Len=Len(My Record)
Position=4
Get #1,Position,MyRecord
Close#1
End Sub

D.Private Sub Command1_Click( )
Dim MyRecord As record,Position
Open"d:\F1.dat"For lnput As #1 Len=Len(MyRecord)
Position=4
Get #1,Position,MyRecord
Close#1
End Sub

答案

参考答案:A

解析: 由于是以随机方式访问该文件,故打开方式为Random。选项C以
Output方式打开,选项D以Input方式打开都是错误的。同时由于要读出第四条记录,故使用Get#语句。

单项选择题 案例分析题
问答题 简答题