Opening .txt file in BASIC 
Author Message
 Opening .txt file in BASIC

Hey,

  I'm a fairly  moderate user of BASIC when it comes to graphics and
drawing. However, I seem to be unable to open a simple text file
within a BASIC program. It's pretty irritating consider all the
knowledge in BASIC I presumed I had. Any help would be greatly
appreciated. Thank's in advance...

-Joe "Lookin' for a signature" - Remove SPAMX when replying..
"Lookin' for a signature"



Tue, 06 Jun 2000 03:00:00 GMT  
 Opening .txt file in BASIC

Quote:

>   I'm a fairly  moderate user of BASIC when it comes to graphics and
> drawing. However, I seem to be unable to open a simple text file
> within a BASIC program. It's pretty irritating consider all the
> knowledge in BASIC I presumed I had. Any help would be greatly
> appreciated. Thank's in advance...

Piece of cake, Joe.  Here is a little program which simply copies file
INPUT.DAT to OUTPUT.DAT, but it should give you the idea.

DIM Rec AS STRING

OPEN "INPUT.DAT" FOR INPUT AS #1
OPEN "OUTPUT.DAT" FOR OUTPUT AS #2

WHILE NOT EOF(1)
   LINE INPUT #1, Rec
   PRINT #2, Rec
WEND

CLOSE 1, 2
END
--
Judson McClendon          This is a faithful saying and worthy of all
Sun Valley Systems        acceptance, that Christ Jesus came into the

(please remove zzz from email id to respond)



Tue, 06 Jun 2000 03:00:00 GMT  
 Opening .txt file in BASIC

Quote:

>drawing. However, I seem to be unable to open a simple text file
>within a BASIC program. It's pretty irritating consider all the
>knowledge in BASIC I presumed I had. Any help would be greatly

You don't say if you want to read from the file or write to it.

To read data from the file try:

OPEN "myfile.txt" for input as #1

If you use the exact syntax shown above then to read from the file you
would use something like (the method of inputting  depends strongly on the
contents of the file and what you want to do with it ;-) :

INPUT #1, val1,val2,val3

The above example would work as you might expect if the file contained rows
of 3 numbers.

The "#1" refers to the number you will use in your program to refer to the
file once you open it.

To write to the file the "open" syntax is:

OPEN "myfile.txt" for output as #1

When you do this it erases any prior contents of the file "myfile.txt" so
be careful!

To write to it one way (again the method you choose depends on what your
desired end result is) is:

PRINT #1, val1,val2,val3



Wed, 07 Jun 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Open TXT files in Visual Basic

2. Adding .TXT files to a VB program without the .TXT file

3. Question: Opening .txt file with vba

4. open txt file and read strings

5. opening a .txt file in ASP

6. open a txt file for the user to view and read

7. Opening a txt file in Excel using VB6

8. how open a file no txt

9. Opening a readme.txt file

10. opening a word (.doc) and Text (.txt) file

11. Open a TXT, DOC file from a command button

12. how to open a 9MB txt file?

 

 
Powered by phpBB® Forum Software