CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2001
    Posts
    14

    Variant Array to single line Text file

    I have an array with a variable number of elements and i'm trying to read it into a text file with all the elements on the same line ! ...

    I'm able to put the array elements in a text file one line at a time using the following:

    Open App.Path & "\test.txt" For Output As #1

    Dim v As Variant
    For Each v In input1
    Print #1, v
    Next

    Close #1

    Where code above this has already read in the values for the Input1() array from an input grid.

    Does someone know how to write it all on the same line ??

    Thanks,

    Shannon.


  2. #2
    Join Date
    Apr 2000
    Posts
    737

    Re: Variant Array to single line Text file

    what you need to do is to join the array into a single string and write to the text file at once like this

    Dim v As Variant
    dim s as string
    s = ""
    For Each v In input1
    s = s + cstr(v)
    Next

    Print #1, s




  3. #3
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Variant Array to single line Text file

    You can use the Join() function. It returns a string created by joining a number of substrings contained in an array. And you can optionally specify a delimiter too.


  4. #4
    Join Date
    Aug 2000
    Location
    KY
    Posts
    766

    Re: Variant Array to single line Text file

    Dim v() As Variant
    ReDim Preserve v(4)
    v(0) = "This"
    v(1) = "is"
    v(2) = "a"
    v(3) = "Test"
    Dim str As String
    str = Join(v, " ")
    Print str



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

Featured