Solved

Write in a text file

Posted on 2001-08-14
13
220 Views
Last Modified: 2012-06-27
How open, append, text files.
and how write in that files.


Tanks!
0
Comment
Question by:juliosb73
  • 3
  • 2
  • 2
  • +5
13 Comments
 
LVL 20

Accepted Solution

by:
hes earned 50 total points
ID: 6386143
For writing
Open "Your file" for output as #1
Print #1 "your Data"
Close #1
For appending

Open "Your file" for Append as #1
Print #1 "your Data"
Close #1

0
 
LVL 2

Expert Comment

by:JanusFury
ID: 6386294
There were typos in that, let me clarify and demonstrate more of File I/O.

Dim FileHandle As Long
FileHandle = FreeFile ' Get free file handle
Open "Filename" For Output as #FileHandle ' Open file for output
Print #FileHandle, "My String" ' Prints string, adds CR+LF after.
Write #FileHandle, FileHandle, "Hello", 5.5 ' Writes variables and values seperated by commas, adds CR+LF after.
Close #FileHandle

Open "Filename" For Append as #FileHandle ' Open file for output, without deleting current contents first
Print #FileHandle, "New Text Appended"
Close #FileHandle

Open "Filename" For Binary As #FileHandle ' Open file for direct binary access. Allows writing almost any types of data, and at any location in the file.
Put #FileHandle, 1, "Hello, World!" ' Get and Put are used to retrieve variables or write variables/data from specific locations in binary files. You cannot use Write and Print in binary files. Note that the 1 (location) is optional.
Close #FileHandle

Good luck :)
Janus
0
 
LVL 1

Expert Comment

by:gigsvoo
ID: 6387314
My recommendation and experience told me, if u have Internet Explorer installed or look for this file in you Windows\ directory: scrrun.dll

Include Microsoft Scripting Runtime in project reference.

This is called FileSystemObject, very powerful and fast.

Do like this:

Dim fso as New FileSystemObject
Dim f as TextStream

set f = fso.OpenTextFile("C:\test.txt",False, ForAppending)
f.write("abc") & vbcrlf
f.close
set f = nothing

This is simple enough, look for MSDN library for details, it have a lots of useful functions and properties.

Hope this helps you.

Thanks

gigsvoo
0
 

Expert Comment

by:costello
ID: 6387716
gigsvoo,

To prevent potential conflicts among the experts, I would like to give you some pointers on being an expert.

        1. You will benefit from carefully reading the entire thread of the question. This will
         prevent you from posting a duplicate suggestion. It also may give you the insight in
         posting *the right answer* that the other experts may have missed. You should not
         repost or copy a previously posted comment as your answer.

        2. Remember, that we are all human. Some people will have a bad day (including you)
         now and then, and may not maintain the most professional of demeanors. That is going
         to happen, so my advice is to always keep in mind that the written medium can be the
         most difficult one in which to express one's thoughts.

        3. If you are not confident that your answer will solve the entire problem without additional
         troubleshooting, then post it as a comment.

        4. If you are confident that your answer will solve the problem without any further troubleshooting,
         post it as an answer.

        5. Some topic areas move very fast and you must post as an answer if you hope to ever get points in
         that thread. The C++ topic area is an example. Experts there will post an answer of 'Answer coming'
         and then post a comment following that with the answer. This is because the Expert needs to actually
         create the data, script etc. Other topic areas move slower, and some of the experts have adopted a
         policy of posting comments only until the customer indicates who should post for the points. You will
         have to feel you way through those areas.

Thank you,
costello
Community Support @ Experts Exchange

0
 
LVL 2

Expert Comment

by:JanusFury
ID: 6388394
PAFSO!
No use FSO for this!
Bad!
Arr!

;P
Janus
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6388468
costello, should you not have forced the rejection of gigsvoo's proposed answer?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 43

Expert Comment

by:TimCottee
ID: 6388479
And please do the same on http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20168512 gigsvoo again I am afraid.
0
 
LVL 3

Expert Comment

by:modder
ID: 6388740
Hi gigsvoo,

Askers can accept any comment made to their questions as the answer. Because of that, a lot of experts never answer a question, but post comments only.

I don't think you necessarily need to adhere to that. If an asker asks "what is 1 + 1" I can't blame the first person in when they lock the question with the answer "2". But most questions aren't as clear cut as that.

In the wonderful world of computing, there often are many different ways to "skin a cat" (as the saying goes).

A lot of times you cannot be *absolutely* sure that your suggestion is going to address the question.

Very often, other participants have already made suggestions.

If any of this is true, you should only post your suggestions as a comment.



Like any web community, Experts-Exchange has a netiquette that members adhere to. Some of this is in the form of "unwritten rules", but a lot of it is described in our member agreement. You can find that here:
http://www.experts-exchange.com/jsp/infoMemberAgreement.jsp

Please also read our tips on comments and answers:
http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp



Thank you for your understanding, and I do expect you to be a bit less eager in the future.



To the asker:
It is in your own interest to reject a proposed answer as soon as possible if it doesn't fully address your problem. As long as a question is "locked" with a proposed answer, a lot of experts will not bother looking at it. Once you've rejected the question, it will become "open" again, which is like an invitation to experts to participate in your question.

Regards

modder
Community Support
0
 
LVL 3

Expert Comment

by:modder
ID: 6388756
PS - please note that I have only force-rejected the proposed answer because of the above reasons. juliosb73, if you think that gigsvoo's answer happens to be the best one, you can still accept it.
0
 
LVL 1

Expert Comment

by:gigsvoo
ID: 6391056
Sorry for all those hassel, i had found out to use Comments after I had posted 2-3 replies using Answer.

Forgive me coz i m new to here.

Apologize to everyone...

gigsvoo
0
 
LVL 3

Expert Comment

by:modder
ID: 6391707
Hi gigsvoo, don't worry about it. We all had to be told the first time we joined, the guidelines are not as clear as they should be :-)

Thank you for taking it as intended. Like I said, Welcome!
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7199958
Hi juliosb73,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept hes's comment(s) as an answer.

juliosb73, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 5

Expert Comment

by:Netminder
ID: 7213381
Per recommendation, force-accepted.

Netminder
CS Moderator
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now