Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to Write to a File

Posted on 2002-03-18
7
Medium Priority
?
127 Views
Last Modified: 2011-09-20
Can anyone explain me how to write to a file? I want to ask the user to give a file name and I need to write some data to the File. How to do this and what are the controls and/or components to be added to the project?
Thanks and Regards,
Badri
0
Comment
Question by:gvsbnarayana
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 150 total points
ID: 6877347
You don't need to add any controls:

Dim intFileHandle As Integer
intFileHandle = FreeFile()
Open "MyOutputFile.txt" For Output As #intFileHandle
Print #intFileHandle,"Here is Some Text"
Close #intFileHandle

Is all that you need to do.

To read from the file open it for "INPUT" and use Line Input #intFileHandle,strLine

To read an entire line back from the file.

There are also other associated functions that you can read up on in the help files.
0
 
LVL 9

Expert Comment

by:kprestage
ID: 6877352
The easiest and fastest way to do this is using the Microsoft Scripting host.  You will need to add a reference to it in your project.  Once you have that, the rest is pretty much self explanatory.  Create a File System Object, and a TextStream

dim fso as new filesystemobject
dim ts as TextStream

use the createtextfile method to create your file based on the path you want

set ts = fso.CreateTextFile(filename)

to write to your file use the write, or writeline method of the textstream

ts.write "Text you want to write to the file"


0
 
LVL 8

Author Comment

by:gvsbnarayana
ID: 6877484
Dear  kprestage ,
    I could not find that component name in my system and the component might be displayed with some other name as the names of the components will be displayed in French as my Operating system is a French version. So Can you give me the name of the dll ?
Thanks and Regards,
Badri
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 18

Expert Comment

by:bobbit31
ID: 6877549
> The easiest and fastest way to do this is using the Microsoft Scripting host

actually, fso has more overhead than the native vb file i/o methods... therefore it is actually slower.  In addition, you need the scrrun.dll (i think that's the one) included w/ your package.  So for simple file i/o (ie. simply reading/writing to a file) i would strongly suggest just using the native routines as shown by TimCottee above.
0
 
LVL 9

Expert Comment

by:kprestage
ID: 6877714
As bobbit31 said, the file name for the dll is scrrun.dll.  It was my understanding that the native VB file I/O commands were being depreciated in VB.net, meaning, don't get accustomed to using them because they may not always be around.
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 6877860
gvsbnarayana,
'Microsoft Scripting Runtime' is not found in components, it is found as a reference.
0
 
LVL 8

Author Comment

by:gvsbnarayana
ID: 6957994
Thank you TimCottee
Here are your points!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

721 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