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 <> "" 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
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 <> "" 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