Visual Programing
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Visual Programing

You are not connected. Please login or register

Basic I/O To Files

2 posters

Go down  Message [Page 1 of 1]

1Basic I/O To Files Empty Basic I/O To Files Mon Aug 25, 2008 4:08 am

Arcady


Moderator
Moderator

Basically there are 3 different methods for reading and writing to files.

Input
This is for reading text from files,

Code:

Dim Data As String 'Declares a variable to hold the data you get from file
Open "C:\new.txt" For input as #1'open it for input
input #1,Data
Close #1'Finally close the file once youve finished reading from it
Call Msgbox(Data)'Display data in a file

That would read one line from the file
To read the whole thing use

Code:

Dim Data,allData As String 'Declares a variable to hold the data you get from file
Open "C:\new.txt" For input as #1'open it for input
do until EOF(1)'Loop until EOF(end of file) = true (or 1)
input #1,Data
alldata = alldata & Data
loop
Close #1'Finally close the file once youve finished reading from it
Call Msgbox(allData)'Display data in a file

Output

Out put completely erases a file and replaces it with your data

Code:
Open "C:\File.txt" for output as #1,
Print #1,yourvar
close #1

Append

Instead of over writing the file with append you can add to it
Code:
Open "File.txt" for append as #1
print #1,data
close #1

2Basic I/O To Files Empty Re: Basic I/O To Files Sat Sep 06, 2008 7:44 pm

k0j0e

k0j0e
Admin
Admin

nice tut! lol!

https://vbforum.iftopic.com

Back to top  Message [Page 1 of 1]

Similar topics

-

» Visual Basic Forum

Permissions in this forum:
You cannot reply to topics in this forum