|
-
Nov 5th, 2006, 07:43 PM
#1
Thread Starter
Hyperactive Member
Data from files
I'm working on a web browser and im stuck on favorites. How would I make it so that vb6 opens up a file (that can be anywhere) and then display the data in a list. And also how to save things into the files so that when you open next time it's there. Thanks
-
Nov 5th, 2006, 07:54 PM
#2
Re: Data from files
Here's a way (needs a ListBox):
VB Code:
'to save it...
Dim ff As Integer: ff = FreeFile
'open it For Append, to only add something...
Open App.Path & "\favorites.dat" For Append As #ff
Print #ff, "http://www.myNewFavoriteSite.com"
Close #ff
'to load it...
Dim i As Integer
Dim ff As Integer: ff = FreeFile
Dim line As String
'add each line to a ListBox...
List1.Clear
Open App.Path & "\favorites.dat" For Input As #ff
Do Until EOF(ff)
Line Input #ff, line
List1.AddItem line
Loop
Close #ff
-
Nov 5th, 2006, 08:42 PM
#3
Thread Starter
Hyperactive Member
Re: Data from files
Ok. Thanks. That helps me
-
Nov 5th, 2006, 09:00 PM
#4
Thread Starter
Hyperactive Member
Re: Data from files
Okay. I have anothe problem. I can't remove items from the list (selected items) and even if I do when I close favorites then go back its still there. How do I fix these? Also if anyone knows how to block popups that would be appreciated also.
Last edited by bluehairman; Nov 5th, 2006 at 09:04 PM.
-
Nov 5th, 2006, 09:47 PM
#5
Re: Data from files
If you wish to remove some item from the list, then you need to open that file in the Output and not Append mode and export the complete list with a simple loop, what would look something like this:
VB Code:
Dim ff As Integer: ff = FreeFile
Dim i As Integer
Open App.Path & "\favorites.dat" For [B]Output[/B] As #ff
For i = 0 To List1.ListCount - 1
Print #1, List1.List(i)
Next i
Close #ff
I used Append before to demonstrate how to just add something to an already existing file. This is something completely different.
-
Nov 6th, 2006, 07:07 PM
#6
Thread Starter
Hyperactive Member
Re: Data from files
But does this code
VB Code:
Dim ff As Integer: ff = FreeFile
Dim i As Integer
Open App.Path & "\favorites.dat" For Output As #ff
For i = 0 To List1.ListCount - 1
Print #1, List1.List(i)
Next i
Close #ff
Remove the selected item?
-
Nov 6th, 2006, 07:09 PM
#7
Re: Data from files
VB Code:
ListBox.RemoveItem ListBox.ListIndex
should remove the selected item.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|