Writing to text files adding extra space
Hey all,
When I try to write to a file putting data from two list boxes it is adding an extra space in between the two list boxes data that is messing up my order when putting them back into the listboxes.
Here is my code... why is it putting a space after lstDisplay1's data is put into the file??
VB Code:
Dim j As Integer
Open Dir & File1.List(File1.ListIndex) For Output Lock Read As #1
For j = 0 To lstDisplay1.ListCount
Print #1, lstDisplay1.List(j)
Next
Print #1, "//"
For j = 0 To lstDisplay2.ListCount
Print #1, lstDisplay2.List(j)
Next
Close #1
Re: Writing to text files adding extra space
You may have ending spaces so trim it:
Trim(lstDisplay1.List(j))
Re: Writing to text files adding extra space
Actually you are going past your index for lstDisplay1.List, which is inserting blanks.
Try:
VB Code:
For j = 0 To lstDisplay1.ListCount - 1
And
For j = 0 To lstDisplay2.ListCount - 1
Re: Writing to text files adding extra space
Quote:
Originally Posted by randem
Actually you are going past your index for lstDisplay1.List, which is inserting blanks.
Try:
VB Code:
For j = 0 To lstDisplay1.ListCount - 1
And
For j = 0 To lstDisplay2.ListCount - 1
Oh... so the list boxes list count starts at 1?
Ok thanks randem.
Re: Writing to text files adding extra space
Quote:
Originally Posted by paralinx
Oh... so the list boxes list count starts at 1?
No the count is how many there are in the list box so if there's two items that means that there will be items 0 and 1.
Re: Writing to text files adding extra space
Quote:
Originally Posted by numtel
No the count is how many there are in the list box so if there's two items that means that there will be items 0 and 1.
in short, its 0 based (but some controls are 1 based which makes no sense, but typical of MS)