Results 1 to 7 of 7

Thread: Data from files

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    343

    Question 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

  2. #2
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Data from files

    Here's a way (needs a ListBox):
    VB Code:
    1. 'to save it...
    2. Dim ff As Integer: ff = FreeFile
    3.  
    4.     'open it For Append, to only add something...
    5.     Open App.Path & "\favorites.dat" For Append As #ff
    6.         Print #ff, "http://www.myNewFavoriteSite.com"
    7.     Close #ff
    8.  
    9. 'to load it...
    10. Dim i As Integer
    11. Dim ff As Integer: ff = FreeFile
    12. Dim line As String
    13.  
    14.     'add each line to a ListBox...
    15.     List1.Clear
    16.         Open App.Path & "\favorites.dat" For Input As #ff
    17.             Do Until EOF(ff)
    18.                 Line Input #ff, line
    19.                     List1.AddItem line
    20.             Loop
    21.         Close #ff

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    343

    Re: Data from files

    Ok. Thanks. That helps me

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    343

    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.

  5. #5
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    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:
    1. Dim ff As Integer: ff = FreeFile
    2. Dim i As Integer
    3.  
    4.     Open App.Path & "\favorites.dat" For [B]Output[/B] As #ff
    5.         For i = 0 To List1.ListCount - 1
    6.             Print #1, List1.List(i)
    7.         Next i
    8.     Close #ff
    I used Append before to demonstrate how to just add something to an already existing file. This is something completely different.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    343

    Re: Data from files

    But does this code
    VB Code:
    1. Dim ff As Integer: ff = FreeFile
    2. Dim i As Integer
    3.  
    4.     Open App.Path & "\favorites.dat" For Output As #ff
    5.         For i = 0 To List1.ListCount - 1
    6.             Print #1, List1.List(i)
    7.         Next i
    8.     Close #ff
    Remove the selected item?

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

    Re: Data from files

    VB Code:
    1. 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
  •  



Click Here to Expand Forum to Full Width