Computing.Net > Forums > Programming > VB text files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VB text files

Reply to Message Icon

Name: Shehzaib
Date: October 22, 2003 at 18:25:33 Pacific
OS: Win XP
CPU/Ram: 1.6 GHz
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: borelli35
Date: October 22, 2003 at 18:35:22 Pacific
Reply:

==================================================
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


0

Response Number 2
Name: Global
Date: October 23, 2003 at 00:59:55 Pacific
Reply:

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 #2

If 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
Global

PS I used to think I was asking 'stupid' questions but the people in here are always happy to help for sure!


0

Response Number 3
Name: Global
Date: October 23, 2003 at 01:03:29 Pacific
Reply:

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!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VB text files

vb text file question www.computing.net/answers/programming/vb-text-file-question/8376.html

vb array using a text file www.computing.net/answers/programming/vb-array-using-a-text-file/5539.html

Adding values in text file via VBS www.computing.net/answers/programming/adding-values-in-text-file-via-vbs/15869.html