Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PUT Statement

Status
Not open for further replies.

joemal

Programmer
Feb 12, 2003
13
MT
I am using the following command, but as a result I am having some garrbage characters at the begining of the file. Can someone help on how this is happening?

Put #1, , "1|" & Trim(txtYear.Text)
 
It's to do with record length. If the variable being written is a variable-length string, Put writes a 2-byte descriptor containing the string length and then the variable. The record length specified by the Len clause in the Open statement must be at least 2 bytes greater than the actual length of the string.

You either need to define the variable length or (easier) open the file for Output and use Print #.
[tt]
Open "c:\fred23.txt" For output As #1
Print #1, "1|" & Trim("1984")
Close #1
[/tt]

Rather than using a constant as the file number, check out the FreeFile function

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top