Link to home
Start Free TrialLog in
Avatar of jennifere
jennifere

asked on

Writing data to a text file

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
Avatar of enari
enari

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.

ASKER CERTIFIED SOLUTION
Avatar of TooKoolKris
TooKoolKris

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jennifere

ASKER

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.