Listviews - outputing to TXT

Hi,

I have a listview with 5 column headers, and a varible amount of rows with data in each column.
How can i output the Listviews data to a file. I have done it all but, im using VBTAB's and that data looks all screwed up and doesn't match the column it is suppoed to be in.

thanks,
LeXienAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VbmasterCommented:
Here's a function to right align text, just call it using code like

  Text = RightAlign("Test", 5)

and you will get the response " Test". Using this you can save the columns like

  Print #Filenr, RightAlign(Column1, 10) & RightAlign(Column2, 20) ...


Function RightAlign(Text As String, Size As Long) As String
 
  If (Len(Text) > Size) Then
    RightAlign = Text
  Else
    RightAlign = Space$(Size)
    Mid$(RightAlign, Size - Len(Text) + 1) = Text
  End If
   
End Function
0
VbmasterCommented:
The comment above.
0
VbmasterCommented:
And here's if you want it Left Aligned.

Function LeftAlign(Text As String, Size As Long) As String
 
  If (Len(Text) > Size) Then
    LeftAlign = Text
  Else
    LeftAlign = Text & Space$(Size - Len(Text))
  End If
   
End Function
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

LeXienAuthor Commented:
i dont get how this coding works. Right align, left align, center... wot? What if i have 5 columns to be positioned?

thanks
0
VbmasterCommented:
And if you want it really 'neat' here's a Center Align function to use, the same way as the other two..

Function CenterAlign(Text As String, Size As Long) As String
 
  If (Len(Text) > Size) Then
    CenterAlign = Text
  Else
    CenterAlign = Space$(Size)
'    Mid$(CenterAlign, ((1 + Size - Len(Text)) \ 2) + 1) = Text
    Mid$(CenterAlign, ((Size - Len(Text)) \ 2) + 1) = Text
  End If
   
End Function

There's one line commented and it looks just like the next one but with one difference, when the text can't be aligned exactly in the middle. As it looks now you will get

  CenterAlign("hej", 4) => "hej "

but if you use the commented line instead of the line after it you get

  CenterAlign("hej", 4) => " hej"
0
VbmasterCommented:
Ah sorry, I thought the use was kinda obvious but I made you a little code sample here you can use, just change the filename and the size of each column to whatever value you find appropriate...

    Dim a As Long
    Dim Filenr As Integer
   
    Open "C:\Test.txt" For Output As #1
    For a = 1 To .Count
      Print #1, LeftAlign(.Item(a).Text, 10);
      Print #1, LeftAlign(.Item(a).SubItems(1), 10);
      Print #1, LeftAlign(.Item(a).SubItems(2), 10);
      Print #1, LeftAlign(.Item(a).SubItems(3), 10);
      Print #1, LeftAlign(.Item(a).SubItems(4), 10)
    Next
    Close #1

This example code will create a file named "C:\Test.txt" with text like

Col1      Col2      Col3      Col4      
Col1      Col2      Col3      Col4      
..
..
..

depending on the Listview's content of course. ,)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LeXienAuthor Commented:
Thanks, just required some re-arranging and it worked fine!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.