Visual Basic Questions and Answers – Writing Data to a Sequential Access File

«
»

This set of Visual Basic Questions and Answers for Campus interviews focuses on “Writing Data to a Sequential Access File”.

1. Reading data from a file is referred to as ________________
a) Reading a file
b) Writing a file
c) Appending a file
d) Executing a file
View Answer

Answer: a
Explanation: In addition to getting data from the keyboard and sending data to the computer screen, an application also can get data from and send data to a file on a disk. Getting data from a f le is referred to as “reading the file,” and sending data to a file is referred to as “writing to the file.”
advertisement

2. Writing data to a file is referred to as ______________
a) Reading a file
b) Writing a file
c) Appending a file
d) Executing a file
View Answer

Answer: b
Explanation: In addition to getting data from the keyboard and sending data to the computer screen, an application also can get data from and send data to a file on a disk. Getting data from a f le is referred to as “reading the file,” and sending data to a file is referred to as “writing to the file.”

3. The file to which data is write is referred to as _______________
a) Input file
b) Output file
c) Random access file
d) Sequential file
View Answer

Answer: b
Explanation: In addition to getting data from the keyboard and sending data to the computer screen, an application also can get data from and send data to a file on a disk. Getting data from a file is referred to as “reading the file,” and sending data to a file is referred to as “writing to the file.” Files to which data is written are called output files, because the files store the output produced by an application.

4. Files that are read by computer are called as _________________
a) Input file
b) Output file
c) Random access file
d) Sequential file
View Answer

Answer: a
Explanation: Files to which data is written are called output files, because the files store the output produced by an application. Files that are read by the computer are called input files, because an application uses the data in these files as input. Most input and output files are composed of lines of text that are both read and written sequentially.

5. Files that read and write in consecutive order are known as _________________
a) Input files
b) Output files
c) Sequential access file
d) Random access file
View Answer

Answer: c
Explanation: Most input and output files are composed of lines of text that are both read and written sequentially. In other words, they are read and written in consecutive order, one line at a time, beginning with the first line in the file and ending with the last line in the file. Such files are referred to as sequential access files, because of the manner in which the lines of text are accessed.
advertisement

6. Files that contain lines of text are known as _______________
a) Binary files
b) Text files
c) Character files
d) Array files
View Answer

Answer: b
Explanation: Most input and output files are composed of lines of text that are both read and written sequentially. In other words, they are read and written in consecutive order, one line at a time, beginning with the first line in the file and ending with the last line in the file. Such files are referred to as sequential access files, because of the manner in which the lines of text are accessed. They also are called text files, because they are composed of lines of text. Examples of text stored in sequential access files include an employee list, a memo, or a sales report.

7. Programmers refer to the sequence of character as ___________________
a) Stream of tokens
b) Stream of characters
c) Stream of bits
d) Stream of bytes
View Answer

Answer: b
Explanation: An item of data—such as the string “Harriet”—is viewed differently by a human being and a computer. To a human being, the string represents a person’s name; to a computer, it is merely a sequence of characters. Programmers refer to a sequence of characters as a stream of characters.

8. In Visual Basic, you use _________________ to write a stream of characters.
a) StreamWriter object
b) StreamWriter class
c) StreamReader object
d) StreamReader class
View Answer

Answer: a
Explanation: Programmers refer to a sequence of characters as a stream of characters. In Visual Basic, you use a StreamWriter object to write a stream of characters to a sequential access file. Before you create the StreamWriter object, you first declare a variable to store the object in the computer’s internal memory. The syntax is as follows:

{Dim | Private} streamWriterVariableName As IO.StreamWriter

The IO in the syntax stands for Input/Output.

advertisement

9. _____________________ is used to open a sequential access file for output.
a) CreateText method
b) AppendText method
c) OpenText method
d) WriteText method
View Answer

Answer: a
Explanation: Creating a StreamWriter object involves opening a sequential access file using one of two methods: CreateText or AppendText. You use the CreateText method to open a sequential access file for output. When you open a file for output, the computer creates a new, empty file to which data can be written. If the file already exists, the computer erases the contents of the file before writing any data to it.

10. _________________ is used to open the sequential file access for append.
a) CreateText method
b) AppendText method
c) OpenText method
d) WriteText method
View Answer

Answer: b
Explanation: You use the AppendText method to open a sequential access file for append. When a file is opened for append, new data is written after any existing data in the file. If the file does not exist, the computer creates the file for you. In addition to opening the file, both methods automatically create a StreamWriter object to represent the file in the application. You assign the StreamWriter object to a StreamWriter variable, which you use to refer to the file in code.

Sanfoundry Global Education & Learning Series – Visual Basic.

advertisement

To practice all areas of Visual Basic for Campus Interviews, here is complete set of 1000+ Multiple Choice Questions and Answers.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn