Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I'm new to VB and I just learned about textfiles...I was hoping if anyone could could answer a question regarding this line of code:Open "c:\name.txt" for Append as #1
What does the "#1" stand for and what should I do if I want to delete something in the file?
TIA!!!
P.S. I know u guys probably think this is a stupid question...Shehzaib.

==================================================
Shehzaib,First of all, there is not a single question that you could ask that would be considered stupid. In fact, the fact that you are intelligent enough to know where to ask and what to ask shows this to be true. "The only stupid question is the one you don't ask".
The number one (#1) is there to define a specific id number to that specific file. Say that you have 2 or more files open. How will you differentiate (and more importantly, how will VB differentiate) the files that you wish to read/write from/to? When you read from a file you might use something like:
input #1,a$
this all can vary but it should give you an idea of what I'm relaying here. I hope this helps clear it up.
borelli35

To further sum up,
The #1 is indeed the id number used for a specific file, for example if you were using more than one:
open "c:\test1.txt" for append as #1
open "c:\test2.txt" for append as #2If you then wished to write only to test1.txt then you would use
print #1, "hello world"
or alternatively
print #2, "hello world"
to print to test2.txt.VB is very straightforward on how it handles text files although there is not really a way to delete a line or characters from a file.
I would write the data that you do need to a new file and leave out what you do not require using string functions.
Also, and I am only going from my experience here but I would be careful in using APPEND, I tend to use OUTPUT instead which re-creates the file and adds to it (when using PRINT) until it encounters a CLOSE.
Just a thought...........!
Regards
GlobalPS I used to think I was asking 'stupid' questions but the people in here are always happy to help for sure!

If you look further down in the posts under the String Search it shows you how to replace text, I didn't know of that!

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |