none
Help with cropping a text file RRS feed

  • Question

  • My program generates a listing of contacts to a text file. My program then reads the contents of the text file and places the text  using the graphicswindow.drawtext command. I have room in my graphics window for a column of six contacts (see the fictitious list below). My problem is that the list keeps growing and the text runs beyond the designated area in my graphics window. Question, Is there a way I can crop the text after six contacts and continue the cropped contact list onto another text file?

    CONTACT 1
    1234 FABRIC WAY
    FABRIC CITY, FB. 12345
    FABER FABINGTON  123.456.7890

    CONTACT 2
    2332 PALMER AVE.
    CHICAGO, IL. 60647
    JOE DOE  312.227.7663

    CONTACT 3
    1234 FABRIC WAY
    FABRIC CITY, FB. 12345
    FABER FABINGTON  123.456.7890

    CONTACT 4
    2332 PALMER AVE.
    CHICAGO, IL. 60647
    JOE DOE  312.227.7663

    CONTACT 5
    1234 FABRIC WAY
    FABRIC CITY, FB. 12345
    FABER FABINGTON  123.456.7890

    CONTACT 6
    2332 PALMER AVE.
    CHICAGO, IL. 60646
    JOE DOE  312.277.7663

    CONTACT 7
    1234 FABRIC WAY
    FABRIC CITY, FB. 12345
    FABER FABINGTON  123.456.7890

     Here is the code that generates the list above;

      'GETS FILES FROM FOLDER AND MAKES ARRAY TO GENERATES LIST
      Contactlist = File.GetFiles(Path +"\Vendors\")
      ContactOutfile = path +"\Vendor List.txt"
      File.WriteContents(ContactOutfile,"")
      'Loop through files in directory and append the contents
      For Contactcount = 1 To Array.GetItemCount(Contactlist)
        Contactfile = Contactlist[Contactcount]
        File.AppendContents(ContactOutfile,File.ReadContents(Contactfile))
      EndFor 

    • Edited by SFC123 Saturday, August 1, 2009 4:25 AM show code
    Saturday, August 1, 2009 3:59 AM

Answers

  • Try the following to create a new file every 6 entries in Contactlist .  Each new file has a counter (number) added to the ContactOutfile .  I don't have the directory structure you have, but I think this should work.  filecount also holds the number of files at the end of the loop.

    'GETS FILES FROM FOLDER AND MAKES ARRAY TO GENERATES LIST
    Contactlist = File.GetFiles(Path +"\Vendors\")
    'Loop through files in directory and append the contents
    filecount = 0
    For Contactcount = 1 To Array.GetItemCount(Contactlist)
      If (Math.Remainder(Contactcount,6) = 1) Then
        filecount = filecount+1
        ContactOutfile = path +"\Vendor List"+filecount+".txt"
        File.WriteContents(ContactOutfile,"")
      EndIf
      Contactfile = Contactlist[Contactcount]
      File.AppendContents(ContactOutfile,File.ReadContents(Contactfile))
    EndFor
    • Marked as answer by SFC123 Saturday, August 1, 2009 6:17 PM
    Saturday, August 1, 2009 8:18 AM
    Moderator

All replies

  • Try the following to create a new file every 6 entries in Contactlist .  Each new file has a counter (number) added to the ContactOutfile .  I don't have the directory structure you have, but I think this should work.  filecount also holds the number of files at the end of the loop.

    'GETS FILES FROM FOLDER AND MAKES ARRAY TO GENERATES LIST
    Contactlist = File.GetFiles(Path +"\Vendors\")
    'Loop through files in directory and append the contents
    filecount = 0
    For Contactcount = 1 To Array.GetItemCount(Contactlist)
      If (Math.Remainder(Contactcount,6) = 1) Then
        filecount = filecount+1
        ContactOutfile = path +"\Vendor List"+filecount+".txt"
        File.WriteContents(ContactOutfile,"")
      EndIf
      Contactfile = Contactlist[Contactcount]
      File.AppendContents(ContactOutfile,File.ReadContents(Contactfile))
    EndFor
    • Marked as answer by SFC123 Saturday, August 1, 2009 6:17 PM
    Saturday, August 1, 2009 8:18 AM
    Moderator
  • Thank you litdev!
    Works like a charm, wonderful programming, thanks once again for your help!
    Saturday, August 1, 2009 6:19 PM