Results 1 to 9 of 9

Thread: Writing an array to a txtfile

  1. #1

    Thread Starter
    Lively Member PCreyght's Avatar
    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    98

    Writing an array to a txtfile

    A probable simple question?!
    How can I print an array to a txt file ??

    Code:
    Dim str(5) as string
    
    for i=1 to 5
       str(i) = i
    next
    
    
    open filename for output as #1
       print #1, str( :confused: ) 
    close #1
    Life is not a problem to solve, It's a reality to experience

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    VB Code:
    1. Dim str(5) As String
    2.  
    3. For i = 1 To 5
    4.    str(i) = i
    5. Next
    6.  
    7.  
    8. Open FileName For Output As #1
    9.     For i = 1 To 5
    10.        Print #1, str(i)
    11.     Next
    12. Close #1

  3. #3
    Addicted Member Supester's Avatar
    Join Date
    Nov 2001
    Location
    The Netherlands
    Posts
    220
    Almost.....try this

    Dim str(5) as string

    open filename for output as #1

    for i=1 to 5
    print #1, str(i)
    next

    close #1

  4. #4
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    wouldn't

    for i = 1 to ubound(str)

    be better?

    just in case

    i mean, i know that your examples work fine, but i'm just making a suggestion

  5. #5
    Addicted Member Supester's Avatar
    Join Date
    Nov 2001
    Location
    The Netherlands
    Posts
    220
    - sorry, wrong thread

  6. #6
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    i think it's just a random question that he wants an answer for

  7. #7
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Originally posted by da_silvy
    wouldn't

    for i = 1 to ubound(str)

    be better?

    just in case

    i mean, i know that your examples work fine, but i'm just making a suggestion
    mm.. yes, or maybe

    for i = LBound(str) to UBound(str)

  8. #8
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    yes

    maybe not for this example, but it will help him in the future

  9. #9
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228

    Cool Sub routine!

    K, we all like this sort of thing written for us, and in case you guys
    havent noticed, the ol' macai dude likes it in Sub\Func format.
    VB Code:
    1. Public Sub ArrayText(TextArray(), _
    2. FileName as String, _
    3. Optional FileNum As Byte = 1, _
    4. Optional CloseOnDone As Boolean = True)
    5.  
    6.  Dim Text As String
    7.  For i = LBound(TextArray) To UBound(TextArray) Step 1
    8.   Text = Text & TextArray(i) & Chr(10) & Chr(10)
    9.  Next i
    10.  Open FileName For Output As #FileNum
    11.  Write #FileNum, Text
    12.  If CloseOnDone = True Then Close #FileNum
    13. End Sub
    There ya' go! Nice and neat and tidy, for the
    PCreyght Meista'!

    Have a good one, guys.
    Laterz
    Luke

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