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

Reading a carriage return in a text file

Status
Not open for further replies.

cassandra

Programmer
Oct 10, 2000
21
US
hi folks,
I need your expertise...I am trying to maintain a text file using a random file access. I have a project with 2 forms. A main form and a data form. I have a list box on the main form where the package ids are displayed. My problem is I need to open the file and display the records on the data form. Here is what is happening:- The first record is displayed correctly in the appropriate controls, but the next record moves one byte over and so does every record after that. In my text file I have a carriage return at the end of record and my guess is this is where my problem is, but try as I might I can't think of a way to get around this. Any suggestions would be welcome. Here is a snippet of the code:

Open "c:\test.txt" For Random As #1 Len = Len(gClient)

If LOF(1) / Len(gClient) > 0 Then ' if file not empty
For iIndex = 1 To LOF(1) / Len(gClient)
Get #1, iIndex, gClient
If gClient.stPackageID <> &quot;&quot; Then
Combo1.AddItem gClient.stPackageID
AddToList (iIndex)
End If
Next iIndex

Sub AddToList(iIndex As Integer)
List1.AddItem gClient.stOrderNumber
List1.ItemData(List1.NewIndex) = iIndex

End Sub
Here is my datatype for the file layout

Public Type customerInfo

stPackageID As String * 14
stfield1 As String * 36
stOrderNumber As String * 20
stOrderID As String * 10
stCompanyName As String * 30
stAttention As String * 30
stAddress1 As String * 30
stAddress2 As String * 30
stCityState As String * 30
stZip As String * 10
End Type

Sorry for rambling, but these are desparate times. Thank you all.

Cassie
 
my first guess is that you're saving UDT's and putting a carriage return at the end of each record so you can view it in a text file, but it doesn't look like your skipping the carriage return when you read it back in, to do this you could add another element to your UDT like

stCityState As String * 30
stZip As String * 10
CrReturn as String * 2

End Type


Sorry if I've misunderstood. Good luck!
 
Thanks Hardkor1001110.

It works now. I changed my DUT and forced the CR when I opened the files.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top