Help needed with Put /Write function

  • Thread starter Thread starter Gero
  • Start date Start date
G

Gero

Guest
Hi !
I want to write variable length strings to a text file.
When I use the "Write" function each line in the file is embedded with " ".
If I use the "Put" function each line begins with some bytes of binary data (called descriptor in the help).
How to write just the data strings (each to a new line) without any other mess ?
 
it's that you're using Write rather than Print. Write will output as typed whereas Print will leave out your "". Put allows you to write to a particular place in a file - update existing records etc - if you need this then it shouldn't put any binary in front, if you don't state where the data should go it will go to the current file pointer. If that is an issue then please post your code. Thanks

I doubt you need it but here's an example in case.

You should be able to do this with:

sub whatever()
on error goto oops
dim lMyfile as long
dim strMyFileName as string
dim strSQL as string
dim rst as Recordset
dim dbs as Database

set dbs= CurrentDb
let strmyFile="C:\path\filename.txt"
let strSQL="Select stuff from...."
set rst=dbs.openrecordset(strsql,4)

let lmyFile=FreeFile

' Append is good as it will create a file that doesn't exist rather than Output which will 'overwrite each the previous file. Really good for doing monthly logs as you can date 'stamp the filename with minimal effort
if rst.recordcount>0 then
open strmyfile for Append shared as #lMyFile
do until rst.eof
print #lmyfile, rst.fields(n).value
' you may need to read all the fields you want to write into another string before 'writing them if you want them all on one line
rst.movenext
loop
close #lmyfile
else
msgbox("No data found in search, no output created")
end if
exit sub
oops:
'error handling stuff
end sub


HTH

Drew

[This message has been edited by KDg (edited 02-29-2000).]
 

Users who are viewing this thread

Back
Top Bottom