Results 1 to 39 of 39

Thread: [RESOLVED] display the content..

  1. #1

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    Resolved [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
    Last edited by merhaba; Jun 8th, 2006 at 03:15 PM.

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    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:
    1. Open "file1" for input as #1
    2. Open "file2" for input as #1
    3. Do while not eof(1)
    4. Line Input #1, fileA
    5. Line Input #2, fileB
    6. Listview.listitems.add  etc
    7.  
    8. Loop
    9. Close #1
    10. Close #2
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    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:
    1. Dim lX as Long
    2.  
    3.    FOr lx = 0 to Ubound(sarrVals)
    4.       lstBox.Add sarrVals(lx) & vbTab & sarrValNames(lx)
    5.    Next

  4. #4

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    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...

  5. #5
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    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)
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  6. #6
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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

  7. #7
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: display the content..

    oh.. and right click.. components.. MS windows common controls 6.0
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  8. #8

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    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?

  9. #9
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: display the content..

    mkcHyperLinks???
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  10. #10

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    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:
    1. Private Sub Command1_Click()
    2. Open "c:\filenum.txt" For Input As #1
    3. Open "c:\filename.txt" For Input As #1
    4. Do While Not EOF(1)
    5. Line Input #1, fileA
    6. Line Input #2, fileB
    7. Listview.listitems.Add fileA, fileB
    8.  
    9. Loop
    10. Close #1
    11. Close #2
    12. End Sub
    what am I missing ?

  11. #11
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: display the content..

    VB Code:
    1. Open "c:\filename.txt" For Input As [B]#2[/B]

  12. #12

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    Re: display the content..

    yes, I noticed that and I corrected but then it says "object required"

  13. #13

  14. #14

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    Re: display the content..

    yes ,
    it says "listview1" shall I remove "1" ?

  15. #15
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: display the content..

    no, this should be
    VB Code:
    1. Listview1.listitems.Add fileA, fileB

  16. #16
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: display the content..

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim fileA As String
    3. Dim fileB As String
    4. Dim lstNew As ListItem
    5.  
    6.    Open "c:\filenum.txt" For Input As #1
    7.    Open "c:\filename.txt" For Input As #2
    8.  
    9.    Do While Not EOF(1)
    10.       Line Input #1, fileA
    11.       Line Input #2, fileB
    12.       Set lstNew = ListView1.ListItems.Add(, , fileA)  'first column
    13.       lstNew.SubItems(1) = fileB 'second column
    14.    Loop
    15.    
    16.    Close #1
    17.    Close #2
    18.    Set lstNew = Nothing
    19. 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.

  17. #17
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: display the content..

    Quote Originally Posted by bushmobile
    no, this should be
    VB Code:
    1. 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?

  18. #18

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    Re: display the content..

    Set lstNew = MyListView.ListItems.Add(, , fileA) [U] 'first column

    object required !!!

  19. #19
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    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.

  20. #20
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    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.
    Last edited by leinad31; Jun 7th, 2006 at 02:10 PM.

  21. #21
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    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

  22. #22

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    Re: display the content..

    run time error 380

    invalid property value for this:
    lstNew.SubItems(1) = fileB 'second column

  23. #23

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    Re: display the content..

    I desperately am in need of a "working complete code"
    Last edited by merhaba; Jun 8th, 2006 at 08:15 AM.

  24. #24
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    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:
    1. Private Sub Command1_Click()
    2. Dim fileA As String
    3. Dim fileB As String
    4. Dim lstNew As ListItem
    5.  
    6.    ListView1.ColumnHeaders.Clear
    7.    ListView1.ColumnHeaders.Add , , "Column 1"
    8.    ListView1.ColumnHeaders.Add , , "Column 2"
    9.    ListView1.ListItems.Clear
    10.  
    11.    Open "c:\filenum.txt" For Input As #1
    12.    Open "c:\filename.txt" For Input As #2
    13.  
    14.    Do While Not EOF(1)
    15.       Line Input #1, fileA
    16.       Line Input #2, fileB
    17.       Set lstNew = ListView1.ListItems.Add(, , fileA)  'first column
    18.       lstNew.SubItems(1) = fileB 'second column
    19.    Loop
    20.    
    21.    Close #1
    22.    Close #2
    23.    Set lstNew = Nothing
    24. End Sub

  25. #25

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    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 ?

  26. #26

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    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 ?

  27. #27
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    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.

  28. #28
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: display the content..

    Post your textfiles.

  29. #29

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    Re: display the content..

    Hi..here are my text files
    Attached Files Attached Files

  30. #30
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: display the content..

    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:
    1. Private Sub Command1_Click()
    2. Dim fileA As String
    3. Dim fileB As String
    4. Dim lstNew As ListItem
    5.  
    6.    ListView1.View = lvwReport  '<=== update
    7.    ListView1.ColumnHeaders.Clear
    8.    ListView1.ColumnHeaders.Add , , "Column 1"
    9.    ListView1.ColumnHeaders.Add , , "Column 2"
    10.    ListView1.ListItems.Clear
    11.  
    12.    Open "c:\filenum.txt" For Input As #1
    13.    Open "c:\filename.txt" For Input As #2
    14.  
    15.    Do While Not EOF(1)
    16.       Line Input #1, fileA
    17.       Line Input #2, fileB
    18.       Set lstNew = ListView1.ListItems.Add(, , fileA)  'first column
    19.       lstNew.SubItems(1) = fileB 'second column
    20.    Loop
    21.    
    22.    Close #1
    23.    Close #2
    24.    Set lstNew = Nothing
    25. End Sub

  31. #31

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    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? ?

  32. #32
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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 :-)

  33. #33
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: [RESOLVED] display the content..

    What will be the output like in the textfile?

  34. #34

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    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...

  35. #35
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    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?

  36. #36

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    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

  37. #37
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    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:
    1. Private Sub Command2_Click()
    2. Dim lX As Long
    3. Dim lstItem1 As ListItem
    4. Dim lstItem2 As ListItem
    5. Dim sLine As String
    6.  
    7.    Open "C:\fileout.txt" For Output As #1
    8.    
    9. On Error Resume Next
    10.    lX = 1
    11.    Do
    12.       Set lstItem1 = Nothing
    13.       Set lstItem2 = Nothing
    14.      
    15.       Set lstItem1 = ListView1.ListItems(lX)
    16.       Set lstItem2 = ListView1.ListItems(lX + 1)
    17.  
    18.       If lstItem2 Is Nothing Then
    19.          Print #1, lstItem1.Text; Tab; lstItem1.SubItems(1)
    20.       Else
    21.          Print #1, lstItem1.Text; Tab; lstItem1.SubItems(1); Tab; Tab; lstItem2.Text; Tab; lstItem2.SubItems(1)
    22.       End If
    23.       lX = lX + 2
    24.    Loop Until lX >= ListView1.ListItems.Count
    25. On Error GoTo 0
    26.  
    27.    Close #1
    28. End Sub

  38. #38

    Thread Starter
    Fanatic Member merhaba's Avatar
    Join Date
    Sep 2002
    Location
    Istanbul,Bartin-Gallipoli(Gelibolu-Canakkale)
    Posts
    601

    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
    Thanks
    Last edited by merhaba; Jun 8th, 2006 at 03:14 PM.

  39. #39
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: [RESOLVED] display the content..

    Try this
    VB Code:
    1. Private Sub Command2_Click()
    2. Dim sLines(49) As String
    3. Dim lArrIdx As Long
    4. Dim lX As Long
    5.  
    6.    lArrIdx = 0
    7.    For lX = 1 To ListView1.ListItems.Count
    8.       sLines(lArrIdx) = sLines(lArrIdx) _
    9.          & ListView1.ListItems(lX).Text & vbTab _
    10.          & ListView1.ListItems(lX).SubItems(1) & vbTab
    11.       lArrIdx = lArrIdx + 1
    12.       If lArrIdx > 49 Then lArrIdx = 0
    13.    Next
    14.    
    15.    Open "C:\fileout.txt" For Output As #1
    16.    For lX = 0 To 49
    17.       Print #1, sLines(lX)
    18.    Next
    19.    Close #1
    20. End Sub

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