File handling in QBASIC Class 10
File handling in QBASIC refers to the process of reading from or writing to files using QBASIC programming language. QBASIC provides several commands and functions to perform file-handling operations, including opening, reading, writing, and closing files.
Here are some of the commonly used file-handling commands and functions in QBASIC:
- OPEN statement: The OPEN statement is used to open a file for reading or writing. It specifies the file name, access mode, and file number.
In QBASIC, there are several file open modes that you can use to read from or write to files. Here are the most commonly used file open modes in QBASIC:
- Input mode: This mode is used to open a file for reading. The file must already exist. The syntax for opening a file in input mode is:
OPEN "filename" FOR INPUT AS #1
- Output mode: This mode is used to open a file for writing. If the file already exists, its contents will be erased. If the file does not exist, a new file will be created. The syntax for opening a file in output mode is:
OPEN "filename" FOR OUTPUT AS #1
- Append mode: This mode is used to open a file for writing, but any data written to the file will be added to the end of the file instead of overwriting existing data. If the file does not exist, a new file will be created. The syntax for opening a file in append mode is:
OPEN "filename" FOR APPEND AS #1
- CLOSE statement: The CLOSE statement is used to close an opened file.
Syntax: CLOSE #filenumber
Example: CLOSE #1
- LINE INPUT statement: The LINE INPUT statement is used to read a line of text from a file.
Syntax: LINE INPUT #filenumber, variable
Example: LINE INPUT #1, name$
- PRINT statement: The PRINT statement is used to write data to a file.
Syntax: PRINT #filenumber, expression
Example 1: PRINT #1, "Hello World!"
- EOF function: The EOF function returns a value of -1 if the end of the file has been reached.
Syntax: EOF(filenumber)
Example 1: DO UNTIL EOF(1) LINE INPUT #1, text$ PRINT text$ LOOP
Netra Koirala
Computer Science Educator
Passionate computer science educator and author. Provides free study notes, practical guides, and tutorials for Class 9, 10, 11, 12, and B.Sc CSIT students in Nepal. Years of teaching experience in computer science fundamentals.
LinkedIn ProfileRelated Posts
Loading related posts…
Computer Science notes, tutorials, MCQs, and educational resources for Nepal students. Covering Class 9, SEE preparation, Class 11, Class 12, SLC, programming, DBMS, networking, HTML, JavaScript, PHP, OOP and more.
Featured Post
Grade 10 Computer Science: Specification Grid & Model Questions
Specification Grid & Model Questions of Computer Science | Grade 10 📚 Examination Resource Specification Grid & M...
