

If you’d opened a file for Input, like this… Open "c:groovymyotherfile.txt" For Input As #1 This inserts the information you pass it direct to the file in #1. …we now want to put information into this file using the Print statement, like this: Print #1, "Hello World!"

Let’s imagine you’ve opened a file for output, like this… Open "c:groovymyfile.txt" For Output As #1 This probably looks completely confusing at the moment, so let’s figure out what it all means. To read from a file we use (Input only): Input #filenumber, variablelist To write to a file we use (Output and Append only): Print #filenumber, expression That’s all fine and dandy, but how do you use each mode after youve opened the file? So, for example, to open a file for output, you’d use the Open statement like this: Open "c:windowsfaq.txt" For Output As #1 In other words, the modes are one way sequential. That’s ’cause once you have read or written to a line, you can’t go back to it unless you close and re-open. Top Tip: You may hear these file modes being referred to as ‘sequential files’. The Input mode opens a file for reading.The Append mode is similar to the Output mode but appends (adds to) an existing file.The Output mode creates a blank file and allows you to write information into it.Use the following list to help you decide… ini files.īut when should you use each mode? Well, it depends on what you want to do. You use these three types to read or write plain text – such as that found in. The file is referred to by the number 1.īefore we dive into the intricacies of using the Open statement, let’s take a peek at three different modes available to us when accessing files:įirst off, let’s take a look at the file modes input, output and append. This example opens the file faq.txt for input (file reading). Here’s an example: Open "c:windowsfaq.txt" For Input As #1ĭon’t worry about the syntax for now, you’ll get used to it. Now, we access files using the Open statement. If you’re interested in accessing databases using Visual Basic, you’d better head down to Karl Moore’s tutorial. Heck, you could even create your own mini word processor!īut don’t confuse this with databases. And that data can be anything – from settings to plain text to pictures. Well, programmers often want to write data to a disk or retrieve data from it. Getting Startedīefore we delve into writing and reading files, let’s ask ourselves a question why would I want to write to a file? Whether it’s likes or gripes, post it on the bulletin board.īut for now, let’s get started. Perhaps even from open to close, if I’m feeling funny.ĭon’t forget that I’d love to hear what you think about this article. In this article, I’ll be covering everything you need to know – from start to finish.
#Vb6 open any file windows
From Microsoft Word to Windows Explorer to Greasy Joe’s Easy Accounts package.īut how do you do this in Visual Basic? Via the Open statement.

The majority of Windows applications handle files.
