Results 1 to 6 of 6

Thread: Writing to text files adding extra space

  1. #1

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    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:
    1. Dim j As Integer
    2.             Open Dir & File1.List(File1.ListIndex) For Output Lock Read As #1
    3.                 For j = 0 To lstDisplay1.ListCount
    4.                     Print #1, lstDisplay1.List(j)
    5.                 Next
    6.                 Print #1, "//"
    7.                 For j = 0 To lstDisplay2.ListCount
    8.                     Print #1, lstDisplay2.List(j)
    9.                 Next
    10.             Close #1

  2. #2

  3. #3
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    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:
    1. For j = 0 To lstDisplay1.ListCount - 1
    2.  
    3. And
    4.  
    5. For j = 0 To lstDisplay2.ListCount - 1

  4. #4

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    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:
    1. For j = 0 To lstDisplay1.ListCount - 1
    2.  
    3. And
    4.  
    5. For j = 0 To lstDisplay2.ListCount - 1
    Oh... so the list boxes list count starts at 1?

    Ok thanks randem.

  5. #5
    Frenzied Member numtel's Avatar
    Join Date
    Apr 2000
    Location
    CA
    Posts
    1,163

    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.

  6. #6
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width