I need to loop in a listview all cells and all column and print the value in tabular mode in a txt file...
but without the last column (is hided i use that for a index)
now i have a liitle difficult
Similar:
| qnsdataID | qnsID | ansID |
-------------------------------------
| qd0001 | qns0002 | ans0012 |
| qd0002 | qns0002 | ans0016 |
| qd0003 | qns0002 | ans0001 |
-------------------------------------
loop in listview element and print in tabular mode
-
- PlatinumLounger
- Posts: 4364
- Joined: 26 Apr 2010, 17:36
-
- Administrator
- Posts: 78549
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: loop in listview element and print in tabular mode
Try this as starting point:
I can't test it since I can't use listview.
Code: Select all
Const c = 25
Dim i As Long
Dim j As Long
Dim m As Long
Dim n As Long
Dim f As Integer
Dim s As String
Dim t As String
f = FreeFile
Open "C:\Output\Test.txt" For Output As #f
m = Me.ListView1.ListItems.Count
n = Me.ListView1.ColumnHeaders.Count
For j = 1 To n - 1
t = Me.ListView1.ColumnHeaders(j).Text
s = s & t & Space(c - Len(t))
Next j
Print #f, Trim(s)
For i = 1 To n
t = Me.ListView1.ListItems(i).Text
s = t & Space(c - Len(t))
For j = 1 To n - 2
t = Me.ListView1.SubItems(j)
s = s & t & Space(c - Len(t))
Next j
Print #f, Trim(s)
Next i
Close #f
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4364
- Joined: 26 Apr 2010, 17:36
Re: loop in listview element and print in tabular mode
hummmmmmm.... see image, pleaseHansV wrote:Try this as starting point:
I can't test it since I can't use listview.Code: Select all
Const c = 25 Dim i As Long Dim j As Long Dim m As Long Dim n As Long Dim f As Integer Dim s As String Dim t As String f = FreeFile Open "C:\Output\Test.txt" For Output As #f m = Me.ListView1.ListItems.Count n = Me.ListView1.ColumnHeaders.Count For j = 1 To n - 1 t = Me.ListView1.ColumnHeaders(j).Text s = s & t & Space(c - Len(t)) Next j Print #f, Trim(s) For i = 1 To n t = Me.ListView1.ListItems(i).Text s = t & Space(c - Len(t)) For j = 1 To n - 2 t = Me.ListView1.SubItems(j) s = s & t & Space(c - Len(t)) Next j Print #f, Trim(s) Next i Close #f
You do not have the required permissions to view the files attached to this post.
-
- cheese lizard
- Posts: 6241
- Joined: 16 Jan 2010, 00:14
- Location: Sydney Australia
Re: loop in listview element and print in tabular mode
What does the error message mean in English ?
Cheers, Claude.
-
- Administrator
- Posts: 78549
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: loop in listview element and print in tabular mode
Try changing the offending line to
Code: Select all
t = Me.ListView1.ListItems(i).SubItems(j)
Best wishes,
Hans
Hans