Results 1 to 11 of 11

Thread: [RESOLVED] Help! !How to Save checked Items In Listview to text file in notepad visual basic 6.0

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2021
    Posts
    9

    Resolved [RESOLVED] Help! !How to Save checked Items In Listview to text file in notepad visual basic 6.0

    How do I only save checked Items In Listview to text file in notepad

    Attachment 181870

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: Help! !How to Save checked Items In Listview to text file in notepad visual basic

    I don't know what that attachment is (I don't randomly click on unknowns).

    Post whatever VB6 (I am assuming you are using Visual Basic 6.0 and not some .Net product) CODE that you wrote to attempt this.

    Sammi

    PS-welcome to the Forum
    Sam I am (as well as Confused at times).

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: Help! !How to Save checked Items In Listview to text file in notepad visual basic

    Well, while you are preparing what you have coded, let me offer this:

    Loop through your listview and add your checked items into a listbox (this is only a TEST for me to understand if you know how to go through the listview and 'save' (albeit temporarily) those items into a listbox). Show me THAT code and I will hint at how to save that information to a text file.
    Sam I am (as well as Confused at times).

  4. #4
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,398

    Re: Help! !How to Save checked Items In Listview to text file in notepad visual basic


  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2021
    Posts
    9

    Re: Help! !How to Save checked Items In Listview to text file in notepad visual basic

    Private Sub Command1_Click()
    Dim i As Integer
    'Save Listview
    For i = 1 To lvwdemo.ListItems.Count
    If lvwdemo.ListItems.Item(i).Checked = True Then

    Dim FileName As String
    FileName = App.Path & "" & Combo1.Text & ".txt"

    ListViewSaveToTextFile lvwdemo, FileName

    End If
    Next i
    End Sub

  6. #6
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: Help! !How to Save checked Items In Listview to text file in notepad visual basic

    Yup...also I have his solution, but want to see what he has already attempted....(maybe nothing yet, just phishing!) :-)
    Sam I am (as well as Confused at times).

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2021
    Posts
    9

    Re: Help! !How to Save checked Items In Listview to text file in notepad visual basic

    my module code

    Public Function ListViewSaveToTextFile(Lvw As ListView, FileName As String) As Boolean

    Dim Li As ListItem
    Dim i As Long
    Dim j As Long
    Dim s() As String
    Dim FNr As Integer

    On Error GoTo Fehler
    FNr = FreeFile
    Open FileName For Output As #FNr

    For i = 1 To Lvw.ListItems.Count
    Set Li = Lvw.ListItems(i)
    ReDim s(Li.ListSubItems.Count)
    s(0) = Li.Text
    For j = 1 To Li.ListSubItems.Count
    s(j) = Li.SubItems(j)
    Next
    If i < Lvw.ListItems.Count Then
    Print #FNr, Join(s, Chr(9))
    Else
    Print #FNr, Join(s, Chr(9));
    End If
    Set Li = Nothing
    Next
    Close #FNr
    ListViewSaveToTextFile = True
    Exit Function

    Fehler:
    Set Li = Nothing
    MsgBox "Fehler: " & Err.Number & vbCrLf & _
    Err.Description, vbCritical
    End Function

  8. #8
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: Help! !How to Save checked Items In Listview to text file in notepad visual basic

    Well...a much simpler method is as follows:


    Code:
    Private Sub Command3_Click()    
        Dim outfile As Integer
        Dim i As Integer
        outfile = FreeFile
        Open App.Path & "\myfile.txt" For Output As #outfile
        For i = 1 To ListView1.ListItems.Count
            If ListView1.ListItems(i).Checked = True Then
                List1.AddItem (ListView1.ListItems(i).Text)
                Print #outfile, ListView1.ListItems(i).Text
            End If
        Next i
        Close #outfile
    End Sub
    did you copy that from some site somewhere, or did you create it?
    Sam I am (as well as Confused at times).

  9. #9

    Thread Starter
    New Member
    Join Date
    Jul 2021
    Posts
    9

    Re: Help! !How to Save checked Items In Listview to text file in notepad visual basic

    I copied it from another website SamOscarBrown

  10. #10

    Thread Starter
    New Member
    Join Date
    Jul 2021
    Posts
    9

    Re: Help! !How to Save checked Items In Listview to text file in notepad visual basic

    and 1000 thanks for the help I really appreciate it SamOscarBrown / Guys

  11. #11
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: [RESOLVED] Help! !How to Save checked Items In Listview to text file in notepad v

    If you are using what I posted, do you understand it?
    loop through the listview and whenever it finds an item (line) that is checked, then add it to the file...
    but first you have to declare and OPEN the file...and always remember to CLOSE it.

    For more info, see MSDN.
    Sam I am (as well as Confused at times).

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