Format array output to .txt file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rizo98
    New Member
    • Jun 2013
    • 18

    Format array output to .txt file

    Hi guys

    How can i format the following code while writing it to a text file?
    Currently it is writing everything on a new line where as i want it to write it in table format which is a table row on every line.

    Code:
     For bytCtr1 = LBound(arrCount(), 1) To UBound(arrCount(), 1)    '1st Dimension
      For bytCtr2 = LBound(arrCount(), 2) To UBound(arrCount(), 2)  '2nd Dimension
        Print #1, arrCount(bytCtr1, bytCtr2)         'Write to Text File
      Next bytCtr2
    Next bytCtr1
    Current form
    Code:
    23
    Name
    14.90%
    33,558,819,050,000.00
    225286973.5
    23
    Name
    14.90%
    23
    Name
    14.90%

    How i want to write to file

    Code:
    23    Name    14.90%    33,558,819,050,000.00    225286973.5    23    Name    14.90%    23    Name    14.90%
    The following url might give more details
    http://bytes.com/topic/access/answers/950303-print-multidimeisonal-array-txt-file
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    You would need to use a 'Build' String concatenating Array Elements and Tabs along the way, something similar to:
    Code:
    For bytCtr1 = LBound(aintTest(), 1) To UBound(aintTest(), 1)    '1st Dimension
      For bytCtr2 = LBound(aintTest(), 2) To UBound(aintTest(), 2)  '2nd Dimension
        strBuild = strBuild & aintTest(bytCtr1, bytCtr2) & vbTab
      Next bytCtr2
    Next bytCtr1
    
    Print #1, Left$(strBuild, Len(strBuild) - 1)

    Comment

    • zmbd
      Recognized Expert Moderator Expert
      • Mar 2012
      • 5501

      #3
      Well, that is one way; however,
      The semicolin will hold the line (as will usually a space).
      The coma will shift to the next 14 character print zone
      A Print#* with an empty string will print a blank line on a new line.
      There's also Tab() and Space() that can be use for formatting. The syntax is in the following link.

      THis is OLD - School BASIC (the language, not yelling :-) )code.
      THe reference is here: Input and Output Keyword Summary Office 2010
      For some reason this information is very hard to find any more so this maybe a link to consider adding to the bookmark list.

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        darn, my favorite site for this information is haveing issues. I may just write something up here tonight about this that may be for the articles.

        Comment

        • rizo98
          New Member
          • Jun 2013
          • 18

          #5
          Thank you guys. the code got me going.
          It needed a little tweak since it printed averything on a single line.

          below is the correct revision. line 6

          Code:
              For bytCtr1 = LBound(aintTest(), 1) To UBound(aintTest(), 1)    '1st Dimension
                For bytCtr2 = LBound(aintTest(), 2) To UBound(aintTest(), 2)  '2nd Dimension
                  strBuild = strBuild & aintTest(bytCtr1, bytCtr2) & vbTab
                Next bytCtr2
                  strBuild = strBuild & vbNewLine
              Next bytCtr1
               
              Print #1, Left$(strBuild, Len(strBuild) - 1)

          Comment

          Working...