[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 :lol:
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?
Re: Listview Saving/loading
Here is what i have so far the Saving seems to be alright, now just need to load :D
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
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:
'Load sites into ListView1:
LoadSites ListView1, App.Path & "\sites.txt"
'Save sites from ListView1:
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.
Re: Listview Saving/loading
Yea thanks i woke up for some reason in the middle of the night and got it working :lol:
Thanks though :thumb:
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
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 :(
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 ^
Re: Listview Saving/loading
Never mind found the answer :D 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 :p