Results 1 to 8 of 8

Thread: [RESOLVED] Listview Saving/loading

  1. #1

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Resolved [RESOLVED] Listview Saving/loading

    I need to save the data in both columns and then load it!

    This project is so huge that now i am so drained i can't figure out how to do this

    The other catch is i need to save it like so...
    Code:
    sitename;url
    sitename;url
    Or a better way if anyone knows of one The url is in the second column, the sitename is in the first. I think i have the saving sort of down just need to continue trying

    Thanks Paul.

    <Edit>
    Sorry there are some more catches if it helps at all, i need to check if the url is already in the text file, and if it is then skip that row.

    Code:
    Open App.Path & "\Sites.txt" For Input As #filenum
            strbuffer = Input(filesize, #filenum)
    Close #FileNumber
    Something like that then just check if strbuffer contains the url, that would be good enough right?
    Last edited by Paul M; Feb 3rd, 2008 at 02:04 AM.

  2. #2

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Listview Saving/loading

    Here is what i have so far the Saving seems to be alright, now just need to load
    Code:
    Public Function SaveSites(ByVal Listv As ListView)
        filenum = FreeFile
    
        If Listv.ListItems.Count > 0 Then
            Open App.Path & "\Sites.txt" For Input As #filenum
            strbuffer = Input(filesize, #filenum)
            Close #filenum
            
            Open App.Path & "\Sites.txt" For Append As #filenum
            
            For i = 1 To Listv.ListItems.Count
                Print #filenum, Listv.ListItems(i) + ";" + Listv.ListItems(i).SubItems(i)
            Next i
    
            Close #filenum
        End If
    End Function
    Code:
    Public Function LoadSites(ByVal Listv As ListView)
    
        'this is totally messed!
        'please forgive me for this function
        'i am just trying things
        
        Dim str1a() As String
        Dim str1b() As String
    
        filenum = FreeFile
        Open App.Path & "\Sites.txt" For Input As #filenum
        str1a() = Split(Input(LOF(1), 1), vbCrLf)
        Close #filenum
        
        str1b() = Split(str1a, ";")
        
        For i = 0 To UBound(str1b) - 1
            Listv.ListItems.Add , , str1b(i)
        Next i
    End Function

  3. #3
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Listview Saving/loading

    Try this:

    Code:
    Public Sub SaveSites(LV As ListView, FilePath As String)
        Dim l As Long, intFF As Integer
        intFF = FreeFile
        With LV
            If .ListItems.Count > 0 Then
                'Remove this line to not delete file before saving.
                SafeKill FilePath
                
                Open FilePath For Append As #intFF
                    For l = 1 To .ListItems.Count
                        Print #intFF, .ListItems(l).Text & ";" & .ListItems(l).SubItems(1)
                    Next l
                Close #intFF
            End If
        End With
    End Sub
    
    Public Sub LoadSites(LV As ListView, FilePath As String)
        Dim strLine As String, strInfo() As String
        Dim intFF As Integer
        intFF = FreeFile
        
        With LV
            .ListItems.Clear
            Open FilePath For Input As #intFF
                If LOF(intFF) > 0 Then
                    Do While Not EOF(intFF)
                        Line Input #intFF, strLine
                        If InStr(1, strLine, ";") > 0 Then
                            strInfo = Split(strLine, ";")
                            .ListItems.Add , , strInfo(0)
                            .ListItems(.ListItems.Count).SubItems(1) = strInfo(1)
                        End If
                    Loop
                End If
            Close #intFF
        End With
        
        Erase strInfo
    End Sub
    
    Public Sub SafeKill(FilePath As String)
        On Error Resume Next
        Kill FilePath
    End Sub
    Then you use it like:

    vb Code:
    1. 'Load sites into ListView1:
    2. LoadSites ListView1, App.Path & "\sites.txt"
    3.  
    4. 'Save sites from ListView1:
    5. SaveSites ListView1, App.Path & "\sites.txt"

    Edit:
    The best way to check if the URL is already there is to check before adding to the ListView.
    Last edited by DigiRev; Feb 3rd, 2008 at 03:06 PM.

  4. #4

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Listview Saving/loading

    Yea thanks i woke up for some reason in the middle of the night and got it working

    Thanks though

  5. #5

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [RESOLVED] Listview Saving/loading

    o.O

    This in my save function is getting Invalid Property Value?

    Code:
    For i = 1 To .ListItems.Count
         Print #filenum, .ListItems(i).Text & ";" & .ListItems(i).SubItems(i)
    Next i

  6. #6

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Listview Saving/loading

    Hmmm the funny thing is this was working a while ago, also i just checked MSDN and done a search can't seem to find anything

  7. #7

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Listview Saving/loading

    Sorry maybe the full code from the routine will help...

    Code:
    filenum = FreeFile
        With ListV
            If .ListItems.Count > 0 Then
                Open filepath For Append As #filenum
                    For i = 1 To .ListItems.Count
                        Print #filenum, .ListItems(i).Text & ";" & .ListItems(i).SubItems(1)
                    Next i
                Close #filenum
            End If
        End With
    Nevermind answer ^
    Last edited by Paul M; Feb 4th, 2008 at 03:15 AM.

  8. #8

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Listview Saving/loading

    Never mind found the answer edited the code in above post, i had the wrong value of i in the first place shows what being away from VB6 for a while does to you

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