Solved

Writing data to a text file

Posted on 2003-11-18
3
1,004 Views
Last Modified: 2010-05-01
I am trying to write data to an output file.  However, when I open output.txt to view my data, there is nothing written.  Here is the section of my code that is writing to the file.  What am I doing wrong, and why is it not writing any data?

Open ("c:output.txt") For Output As #2
   
For j = 1 To UBound(lines)
    str2 = str2 + getField(j, 2) + "|" + getField(j, 4) + vbCrLf
    Print #2, str2
    frmTest.Text1.Text = str2
Next
Close #2
0
Comment
Question by:jennifere
3 Comments
 

Expert Comment

by:enari
ID: 9773259
Hi!

Your code is correct to write a file.
Which leads me to beleive that your str2 does not have any value.

If you change str2 = "testing my file" , you will see "testing my file" in the output.txt file,

however does:
"lines" have a value and is it greater than one ?
does getField(j,2) have a value?

you can find out by doing a "debug.print getfield(j,2) " and so on.

0
 
LVL 9

Accepted Solution

by:
TooKoolKris earned 125 total points
ID: 9773481
Open ("c:output.txt") For Output As #2

This statement is not a correct path statement it should have a backslash in the path like this:

(c:\output.txt") you forgot to add the "\"
0
 

Author Comment

by:jennifere
ID: 9773649
I have modified the code to your suggestion in my last question, because this one was not working for me.  I knew it was something simple I was overlooking.  That explains what I was doing wrong...  Thanks again.  
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…

758 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

23 Experts available now in Live!

Get 1:1 Help Now