niusouti.com

假定在工程文件中有一个标准模块,其中定义了如下记录类型:Type BooksName As String*10TelNuin As String*20End Type要求在执行事件过程Command1_Click时,在顺序文件Person.txt中写入一条记录。将以下程序补充完整。Private Sub Command1_Clickk()DimB As Booksopen"c:\person.txt"For output As 1B.Name=InputBox("请输入姓名")B.TelNum=Input

题目

假定在工程文件中有一个标准模块,其中定义了如下记录类型:Type Books

Name As String*10

TelNuin As String*20

End Type

要求在执行事件过程Command1_Click时,在顺序文件Person.txt中写入一条记录。将以下程序补充完整。

Private Sub Command1_Clickk()

DimB As Books

open"c:\person.txt"For output As 1

B.Name=InputBox("请输入姓名")

B.TelNum=InputBox("请输入电话号码")

write 1,______

close 1

End Sub


相似考题
更多“假定在工程文件中有一个标准模块,其中定义了如下记录类型:Type Books Name As String*10 TelNuin ”相关问题
  • 第1题:

    设在工程文件中有—个标准模块,其中定义了如下记录类型:Type Books Name As String *10 TelNum As String*20End Type在窗体上画—个名为Command1的命令按钮,要求当执行事件过程Command1_Click时,在顺序文件Petson.txt中写入一条Books类型的记录。下列能够完成该操作的事件过程是 ______。

    A.Private Sub Command1_ Click() Dim B As Books Open "Person.txt" For Output As #1 B. Name=InputBox(“输入姓名”) B. TelNum=InputBox(“输入电话号码”) Write #1, B. Name, B. TelNum Close #1End Sub

    B.Private Sub Command1_ Click() Dim B As Books Open "Person.txt" For Input As #1 B. Name=InputBox(“输入姓名”) B.TelNum=InputBox(“输入电话号码”). Print #1, B. Name, B.TelNum Close #1End Sub

    C.Private Sub Command1_Click() Dim B As Books Open "Person.txt" For Output As #1 B.Name= InputBox(“输入姓名”) B.TelNum=InputBox(“输入电话号码”) Write #1,B Close #1End Sub

    D.Private Sub Command1_ Click() Open "Person. txt" For Input As #1 Name=InputBox(“输入姓名”) TelNum=InputBox(“输入电话号码”) Print #1, Name, TelNum Close #1End Sub


    正确答案:A
    解析:文件的打开格式为:
    Open文件名(可包含路径)For文件打开方式[Access 访问权限][Shared]As文件号文件打开方式有如下几种:
    Output:指定顺序输出文件。
    Input:指定顺序输入文件。
    Append:指定顺序输出方式。与Output不同的是,当用Append方式打开文件时,文件指针被定位在文件末尾。
    如果对文件执行写操作,则写入的数据附加到原来文件的后面。
      题目要求当执行事件过程Command1_Click时,在顺序文件Person.txt中写入一条Books类型的记录,因此Person.txt文件是Output方是打开的,因此选项B、D错误。数据写入磁盘文件所用的命令是Write #或Print #命令,形式为Print #件号,[输出列表],Write #破件号,表达式。选项A、D中的表达方式都是正确的。记录变量的输入和输出都必须指明到记录元素。格式为:记录变量.元素名。选项D中是直接在过程中引用记录变量,因此是错误的。

  • 第2题:

    设在工程文件中有一个标准模块,其中定义了下列记录类型:

    Type Books

    Name As String*10

    TelNum As String*20

    End,Type

    在窗体上画一个名为Command1的命令按钮,要求当执行事件过程Command1 Click 时,在顺序文件Person.txt中写入一条Books类型的记录。下列能够完成该操作的事件过程是( )。

    A.Private Sub Command1 Click( )

    Dim B AS Books

    Open"Person txt"For Output As#1

    Name=InputBox(”输入姓名”)

    relNum=lnputBox(”输入电话号码”)

    Wlite#1 B Name,B TelNum

    Ch,se#1

    End Sub

    B.Private Sub Command1 Click( )

    Dim B AS Books

    Open"Person txt"For Input As#1

    >Name=InputBox("输入姓名")

    TelNum=InputBox("输入电话号码")

    Print#1,B.Name,B.TelNam

    Close#1

    End Sub

    C.Private Sub Command1 Click( )

    Dim BAS Books

    Open"Person txt"For Output As#1

    Name=InputBox("输入姓名")

    TelNum=InputBox("输入电话号码")

    Write#1,B

    Close#1

    End Sub

    D.Private Sub Commandl Click( )

    Open"Person txt"For Input As#1

    Name=lnputBox("输入姓名")

    TelNum=lnputBox("输入电话号码")

    Prim#1 Name TelNum

    Close#1

    End Sub


    正确答案:A
    A。【解析】Type语句用于在模块级别(过程外的任何代码都被看作模块级别代码,必须先列出声明,随后列出过程)中定义一个用户自己的数据类型,本质上是一个数据类型集合,它含有一个至一个以上的成员。每个成员可以被定义为不同的数据类型。当声明自定义类型变量后,可通过“变量名.成员名”来访问自定义变量中的元素。VisualBasic程序中关于文件的操作,主要是先打开一个文件,然后对这个文件进行读或写的操作,操作完成后,关闭这个文件。打开文件的基本格式为:OpenFileNameForModeAs#FileNumber。打开方式主要有Output、Append、Input、Random等几种,Output、Append、Input方式打开的文件进行的读写操作都是以顺序方式进行的,其中Output、Append打开的文件主要用来输出数据,与Print#、Write#等方法配合使用;以Input方式打开的:(件主要用来读入数据,它与Input#、LineInput#语句配合使用。本题中,选项B和选项D均是以Input方式打开文件,显然错误,选项C中向顺序文件中写入记录的语句错误,正确答案只有选项A。

  • 第3题:

    设在工程文件中有一个标准模块,其中定义了如下记录类型: Type Books   Name As String * 10   TelNum As String * 20 End Type 在窗体上画一个名为Command1的命令按钮,要求当执行事件过程Command1_Click时,在顺序文件Person.txt中写入一条Books类型的记录。下列能够完成该操作的事件过程是________。

    A.Private Sub Command1_Click()Dim B As BooksOpen 'Person.txt' For Output As #1B.Name=InputBox('输入姓名')B.TelNum=InputBox('输入电话号码')Write #1, B.Name, B.TelNumClose #1End Sub#B.Private Sub Command1_Click()Dim B As BooksOpen 'Person.txt' For Input As #1B.Name=InputBox('输入姓名')B.TelNum=InputBox('输入电话号码')Print #1, B.Name, B.TelNumClose #1End Sub#C.Private Sub Command1_Click()Dim B As BooksOpen 'Person.txt' For Output As #1B.Name=InputBox('
    添加模块

  • 第4题:

    假定在工程文件中有一个标准模块,其中定义了如下记录类型 Type Books Name As String*10 TelNum As String*20 End Type 要求当执行事件过程Commandl_Click时,在顺序文件Person.txt中写入一条记录。下列能够完成该操作的事件过程是:

    A. Prirate Sub Commandl Click() Dim B As Books Open"C:\Person.txt"For Output As #1B.Name=InputBox("输入姓名")B.TelNum=InputBox("输入电话号码") Write #1,B.Name,B.TelNum Close #1 End Sub

    B.Pdrate Sub Commandl Cliok() Dim B As Books Open"c:\Person.txt"For Input As #1B.Name=InputBox("输入姓名")B.TeINum=InputBox("输入电话号码") Print #1,B.Name,B.TelNum Close #1 End Sub

    C.Private Sub Commandl Click() Dim B As Books Open"c:\Person.txt"For Output As #1 Name=InputBox("输入姓名") TelNunl=InputBox("输入电话号码") Write #1,B Close #1 End Sub

    D.Private Sub Commandl Click() Dim B As Books Open"c:\Person.txt"For Input As #1 Name=InputBox("输入姓名") Temum=InputBox("输入电话号码") Write #1,B.Name,B.TelNuin Close #1 End Sub


    正确答案:A
    解析:A选项正确。
    B选项向文件中输出内容,打开方式应当为For Output。
    C选项记录变量不可以对元素整体输入输出。
    D选项记录变量的输入和输出都必须指明到记录元素。格式为:记录变量.元素名。

  • 第5题:

    假定在工程文件中有一个标准模块,其中定义了如下记录类型: Type Books Name As String*10 TelNum As String*20 End Type 要求当执行事件过程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 Output 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 Name=InputBox("输入姓名") TelNum=InputBox("输入电话号码") Print #1, B Close #1 End Sub

    D.Private Sub Command1_Click() Dim B As Books Open "c:\Person txt" For Output As #1 Name=InputBox("输入姓名") TelNum=InputBox("输入电话号码") Print #1, B Name, B. TelNum Close #1 End Sub


    正确答案:A
    解析:要向顺序文件中写入记录必须用For Output参数打开文件,然后用Print#或Write#语句将内容写入文件,因此选项B和选项D不正确;又因为自定义数据类型变量的引用要用“变量名. 变量元素名”,所以选项C不正确。故本题的正确答案只有选项A。