-
[RESOLVED] display the content..
Hi,
I have a text file (textNum.txt)having numbers from 1 to 100 (1,2,3,4......100)
and I have another text file (textName.txt) that contains names for the numbers (one,two,three,four....one hundred)
what I need to do is to display the content of both files in a listbox having two or more columns..
Any help would be greatly appriciated
-
Re: display the content..
listbox does not have columns (unless in Access)
try a list view
but basically open both files... then read line by line of each
something like this
VB Code:
Open "file1" for input as #1
Open "file2" for input as #1
Do while not eof(1)
Line Input #1, fileA
Line Input #2, fileB
Listview.listitems.add etc
Loop
Close #1
Close #2
-
Re: display the content..
Open both textfiles and get their text streams... use Split(strTextstream, ",") on both text streams, you should now have two arrays of same size.
VB Code:
Dim lX as Long
FOr lx = 0 to Ubound(sarrVals)
lstBox.Add sarrVals(lx) & vbTab & sarrValNames(lx)
Next
-
Re: display the content..
Actually there is a "columns" in listbox properties window.
and..
I cant see any "list-view" in my toolbox ....then I right clicked to add one..but there is none in the component section either...
-
Re: display the content..
ok.. but columns is for a horizontal scroll bar setup.. so... its ONE list but shows 2 columns at a time
Like in explorer - view Lists (instead of Icon, Details.. etc)
-
Re: display the content..
It *is* there...look under Microsoft Windows Common Controls (6.0 I think...any should work)..you should see an icon with 3 boxes and 2 underneath
-
Re: display the content..
oh.. and right click.. components.. MS windows common controls 6.0
-
Re: display the content..
Okay, thanks
I managed to add all those controlers in the toolbox..
But,I added the "mkcHyperLinks" to the listbox, then I noticed that it is not there ? what should I do to make it stay there all the time?
-
Re: display the content..
-
Re: display the content..
I used "mkcHyperLinks" to give a link to text file in one of my recent projects..
I did not mean it for this thread....
As for this thread I get an error message saying "file already open" ???
VB Code:
Private Sub Command1_Click()
Open "c:\filenum.txt" For Input As #1
Open "c:\filename.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, fileA
Line Input #2, fileB
Listview.listitems.Add fileA, fileB
Loop
Close #1
Close #2
End Sub
what am I missing ?
-
Re: display the content..
VB Code:
Open "c:\filename.txt" For Input As [B]#2[/B]
-
Re: display the content..
yes, I noticed that and I corrected but then it says "object required"
-
Re: display the content..
do you have a listview called 'listview'?
-
Re: display the content..
yes ,
it says "listview1" shall I remove "1" ?
-
Re: display the content..
no, this should be
VB Code:
Listview1.listitems.Add fileA, fileB
-
Re: display the content..
VB Code:
Private Sub Command1_Click()
Dim fileA As String
Dim fileB As String
Dim lstNew As ListItem
Open "c:\filenum.txt" For Input As #1
Open "c:\filename.txt" For Input As #2
Do While Not EOF(1)
Line Input #1, fileA
Line Input #2, fileB
Set lstNew = ListView1.ListItems.Add(, , fileA) 'first column
lstNew.SubItems(1) = fileB 'second column
Loop
Close #1
Close #2
Set lstNew = Nothing
End Sub
ListView is the class name, either use the default ListView1 or use another name for your listview control (eg. MyListView in this code).
EDIT: I renamed the control to ListView1 since you said this is the name your using.
-
Re: display the content..
Quote:
Originally Posted by bushmobile
no, this should be
VB Code:
Listview1.listitems.Add fileA, fileB
That's just the index and the key, there's no text.
I'm confused. Is he showing both values in two columns? Or just the number names in one column with the values as indices?
-
Re: display the content..
Set lstNew = MyListView.ListItems.Add(, , fileA) [U] 'first column
object required !!!
-
Re: display the content..
Quote:
Originally Posted by leinad31
That's just the index and the key, there's no text.
I'm confused. Is he showing both values in two columns? Or just the number names in one column with the values as indices?
i was just correcting the object in that line - i don't really use the listview, so i wasn't trying to ammend that bit.
-
Re: display the content..
Merhaba,
MyListView was just an assumed listview control name. I updated it to the default ListView1, since you said in post#14 that your using that control name.
-
Re: display the content..
Quote:
Originally Posted by bushmobile
i was just correcting the object in that line - i don't really use the listview, so i wasn't trying to ammend that bit.
I just got lost on the flow of the discussion :) I thought someone made a suggestion to use a single column instead... if so an additional comma would have been all that was needed in that line.
ListView1.ListItems.Add fileA, , fileB
-
Re: display the content..
run time error 380
invalid property value for this:
Quote:
lstNew.SubItems(1) = fileB 'second column
-
Re: display the content..
I desperately am in need of a "working complete code" :cry:
-
Re: display the content..
people usually create the columns at design time... Since your not familiar with listview and that will take some explanation then we will create the columns (ColumnHeaders collection) at run time instead.
VB Code:
Private Sub Command1_Click()
Dim fileA As String
Dim fileB As String
Dim lstNew As ListItem
ListView1.ColumnHeaders.Clear
ListView1.ColumnHeaders.Add , , "Column 1"
ListView1.ColumnHeaders.Add , , "Column 2"
ListView1.ListItems.Clear
Open "c:\filenum.txt" For Input As #1
Open "c:\filename.txt" For Input As #2
Do While Not EOF(1)
Line Input #1, fileA
Line Input #2, fileB
Set lstNew = ListView1.ListItems.Add(, , fileA) 'first column
lstNew.SubItems(1) = fileB 'second column
Loop
Close #1
Close #2
Set lstNew = Nothing
End Sub
-
Re: display the content..
Hey, it works...
But I can see only the numbers broken in two rows
1,2,3,4
5,6
I think I need the name of that number, too
as:
1 one
2 two
3 three
........
20 twenty
what is missing ?
-
Re: display the content..
what about reading all the text in the "textNum.txt" file
and give it a for loop
and do the same for the "textName.txt" file
dim nums as string
dim sname as string
for nums 1 to 100
for sname 1 to 100
list1.additems nums,snames
next
next
something like this not possible ?
-
Re: display the content..
It should be showing in the second column... try scroling the listview and adjusting column widths with the mouse at run time.
-
Re: display the content..
-
2 Attachment(s)
Re: display the content..
Hi..here are my text files
-
Re: display the content..
Quote:
But I can see only the numbers broken in two rows
1,2,3,4
5,6
Oooops we forgot to set the listview in report view. Here...
VB Code:
Private Sub Command1_Click()
Dim fileA As String
Dim fileB As String
Dim lstNew As ListItem
ListView1.View = lvwReport '<=== update
ListView1.ColumnHeaders.Clear
ListView1.ColumnHeaders.Add , , "Column 1"
ListView1.ColumnHeaders.Add , , "Column 2"
ListView1.ListItems.Clear
Open "c:\filenum.txt" For Input As #1
Open "c:\filename.txt" For Input As #2
Do While Not EOF(1)
Line Input #1, fileA
Line Input #2, fileB
Set lstNew = ListView1.ListItems.Add(, , fileA) 'first column
lstNew.SubItems(1) = fileB 'second column
Loop
Close #1
Close #2
Set lstNew = Nothing
End Sub
-
Re: display the content..
okay...That's it...
And my last wish is to save the content of listview to a text file
How should we modify the code? ?
-
Re: [RESOLVED] display the content..
All you wanted to do was re-order the data? You could have done that with a textbox, and wouldn't have needed to faff around with listview :-)
-
Re: [RESOLVED] display the content..
What will be the output like in the textfile?
-
Re: [RESOLVED] display the content..
it would be very nice if we can modify the textfile...
50 items in each columns in the text file so that I can have all datas on a single paper
when printed...
-
Re: [RESOLVED] display the content..
So there's a limit on the number of items per column in the printout?
How many columns will the printout have? 2? 4?
-
Re: [RESOLVED] display the content..
Quote:
Originally Posted by leinad31
So there's a limit on the number of items per column in the printout?
How many columns will the printout have? 2? 4?
four...4
-
Re: [RESOLVED] display the content..
Its easiest to alternate between the two column groups (1 group is 2 columns) rather than printing 1-50 in first column group then 50-100 in the second column group.
VB Code:
Private Sub Command2_Click()
Dim lX As Long
Dim lstItem1 As ListItem
Dim lstItem2 As ListItem
Dim sLine As String
Open "C:\fileout.txt" For Output As #1
On Error Resume Next
lX = 1
Do
Set lstItem1 = Nothing
Set lstItem2 = Nothing
Set lstItem1 = ListView1.ListItems(lX)
Set lstItem2 = ListView1.ListItems(lX + 1)
If lstItem2 Is Nothing Then
Print #1, lstItem1.Text; Tab; lstItem1.SubItems(1)
Else
Print #1, lstItem1.Text; Tab; lstItem1.SubItems(1); Tab; Tab; lstItem2.Text; Tab; lstItem2.SubItems(1)
End If
lX = lX + 2
Loop Until lX >= ListView1.ListItems.Count
On Error GoTo 0
Close #1
End Sub
-
Re: [RESOLVED] display the content..
.I think I need more than two columns
to divide all 300 items by 6 so that each columns display 50 items...
how should I limit the number of items equally for each column?
..I have only two columns in notepad when I run the code above :sick:
Thanks
-
Re: [RESOLVED] display the content..
Try this
VB Code:
Private Sub Command2_Click()
Dim sLines(49) As String
Dim lArrIdx As Long
Dim lX As Long
lArrIdx = 0
For lX = 1 To ListView1.ListItems.Count
sLines(lArrIdx) = sLines(lArrIdx) _
& ListView1.ListItems(lX).Text & vbTab _
& ListView1.ListItems(lX).SubItems(1) & vbTab
lArrIdx = lArrIdx + 1
If lArrIdx > 49 Then lArrIdx = 0
Next
Open "C:\fileout.txt" For Output As #1
For lX = 0 To 49
Print #1, sLines(lX)
Next
Close #1
End Sub