单选题
在E盘当前目录文件夹下建立一个名为“Student.txt”的随机文件,要求用InputBox函数输入5个学生的姓名(StuName)、年级(StuGrade)和年龄(StuAge)。在程序中有以下记录类型和窗体的事件过程,请选择正确的语句完成程序( )。 Private Type student StuName As String * 10 StuGrade As String * 10 StuAge As Integer End Type Private Sub Form Click() Dim s As student Open "c:/student.txt"For Random As#1 Len=Len(s) For i=1 To 5 s.StuName=InputBox("请输入姓名") s.StuGrade=InputBox("请输入年级号") s.StuAge=Val(InputBox("请输入年龄")) ______ Next i Close #1 End Sub
【正确答案】
C
【答案解析】[解析] 本题考查文件操作。题目中要求以随机的方式(Random)打开一个文件,打开文件的格式为:Open FileName For Random As#文件号[Len=记录长度],然后以Put命令写入一条记录,格式为:Put[#]文件号,[记录号],变量名。若省略记录号,表示存当前记录号下写入记录型变量,“,”不可以省略。