Solved

Writing data to a text file

Posted on 2003-11-18
3
1,006 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

910 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

24 Experts available now in Live!

Get 1:1 Help Now