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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbcrlf (chr(13) & chr(10)) help!

Status
Not open for further replies.

nimarii

MIS
Joined
Jan 26, 2004
Messages
213
Location
US
i have code that loops through a recordset, and calls a function to write a line of data in a text file that was created. the function that is called has a vbcrlf at the end, so that the data will start on a new line each time.

the resulting text file has all the data correctly placed, with one exception, every few lines or so, there will be a completely blank line.

here's the code:

For lngrowcount = 0 To NumRecs - 1

Do While Not detailsrec.EOF
strproductrecord = Generate_Product_Record(True, False, lngproductcount, lngelementcount)
Loop

If strproductrecord <> "" Then
Print #refnum2, strproductrecord
End If
Next

Function Generate_Product_Record(ByVal boolbtnFlag As Boolean, ByVal boolFinalProduct As Boolean, ByVal lngproductcount As Long, ByVal lngelementcount As Long)

strproductrecord = strproductrecord & Left(lngcallid & Space(10), 10)
strproductrecord = strproductrecord & Left(lngordernumber & Space(10), 10)
strproductrecord = strproductrecord & Left(newrec("btn") & Space(10), 10)
strproductrecord = strproductrecord & vbcrlf
End Function

Does anyone know how i can prevent the blank lines from occurring?? I'd greatly appreciate any help!
 
You don't need to add the CR-LF. Each Print # statement goes on a new line in the text file.

 
thanks for the reply!
unforuntately, the way the code runs, it has a string thats constantly added to it, so unless the loop starts over, it will all be on one line with out the vbcrlf (sorry if that didn't make much sense)

i think maybe a way to solve this would be to identify if i'm on the last record of the detailsrec, and if so, then don't use vbcrlf...?

as in:
if not lastrecord then
strproductrecord = strproductrecord & vbcrlf
end if

what do you think?
 
i think maybe a way to solve this would be to identify if i'm on the last record of the detailsrec, and if so, then don't use vbcrlf...?

as in:
if not lastrecord then
strproductrecord = strproductrecord & vbcrlf
end if

The challenge would be determining if you are at the last record.

Another approach would be to put the print command inside the loop. Then you would never need to add the CR-LF. Like this:

Code:
Do While Not detailsrec.EOF
    strproductrecord = ""
    strproductrecord = Generate_Product_Record(True,False,lngproductcount, lngelementcount)

    If strproductrecord <> "" Then
       Print #refnum2, strproductrecord
    End If
Loop
 
If the endless concatenation is the problem (as it appears) then you can solve this initialising the string inside the function

Code:
Function Generate_Product_Record(ByVal boolbtnFlag As Boolean, ByVal boolFinalProduct As Boolean, ByVal lngproductcount As Long, ByVal lngelementcount As Long)

[B]strproductrecord =""[/B]
strproductrecord = strproductrecord & Left(lngcallid & Space(10), 10)
strproductrecord = strproductrecord & Left(lngordernumber & Space(10), 10)
strproductrecord = strproductrecord & Left(newrec("btn") & Space(10), 10)

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top