Results 1 to 17 of 17

Thread: Loading files

  1. #1

    Thread Starter
    Addicted Member Stephen Bazemore's Avatar
    Join Date
    Aug 2000
    Location
    North Carolina
    Posts
    158
    How would I go about loading a text file, or an ini file into a listbox? I cant figure it out.
    Stephen Bazemore
    Email:[email protected]

  2. #2
    Guest
    Code:
    Public Sub List_Load(TheList As Listbox, FileName As String)
    On Error Resume Next
    Dim TheContents As String
    Dim fFile As Integer
    fFile = FreeFile
     Open FileName For Input As fFile
       Do
         Line Input #fFile, TheContents$
            TheList.Additem TheContents$
       Loop Until EOF(fFile)
     Close fFile
    End Sub
    
    'Usage:
    
    Call List_Load(List1, "C:\MyFile.txt")

  3. #3

    Thread Starter
    Addicted Member Stephen Bazemore's Avatar
    Join Date
    Aug 2000
    Location
    North Carolina
    Posts
    158

    Talking

    Thanks matt.. just what i needed.
    Stephen Bazemore
    Email:[email protected]

  4. #4
    Addicted Member Tiovital's Avatar
    Join Date
    Apr 2000
    Posts
    249
    Try,

    Dim Inputfile As String
    Dim InputRec As String
    Open InputFile For Input As #1

    Do While Not EOF(1)
    DoEvents
    Line Input #1, IputRec
    list1.Additem InputRec
    Loop

    Close #1

    Regards

  5. #5

    Thread Starter
    Addicted Member Stephen Bazemore's Avatar
    Join Date
    Aug 2000
    Location
    North Carolina
    Posts
    158
    ahh, sorry tio didnt see your post, but thanks.
    sorry to bug you again ..
    but what would i need to do to save the file with the data in the listbox?

    [Edited by Stephen Bazemore on 10-08-2000 at 01:21 AM]
    Stephen Bazemore
    Email:[email protected]

  6. #6
    Addicted Member Tiovital's Avatar
    Join Date
    Apr 2000
    Posts
    249
    Matthew ,
    Sorry For My poor sample, I didnt know that you r already answer, Your Sample Is The Best ONE!!!.

    Btw, How can i used COLOR in the VB-World Form?


    Best Regards
    Tio

  7. #7

    Thread Starter
    Addicted Member Stephen Bazemore's Avatar
    Join Date
    Aug 2000
    Location
    North Carolina
    Posts
    158
    If your talking about how to add color to your code follow this link http://forums.vb-world.net/index.php?action=bbcode and it will tell you exactly how.
    Stephen Bazemore
    Email:[email protected]

  8. #8
    Guest
    You mean code tags?

    [code]Your code[/code]

    For more, check out the link above.

  9. #9
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Originally posted by Stephen Bazemore
    But what would i need to do to save the file with the data in the listbox?
    This function:
    Code:
    Public Sub List_Save(TheList As ListBox, FileName As String)
    On Error Resume Next
    Dim TheContents As String
    Dim fFile As Integer
    fFile = FreeFile
    'this functions overwrites the file
    'so it deletes the file first if it's already there
    If Dir$(FileName) <> "" Then
        'delete the file
        Kill FileName
    End If
    Open FileName For Output As fFile
        For i = 0 To (TheList.ListCount - 1)
            Print #1, TheList.List(i)
        Next
    Close fFile
    End Sub
    Usage:
    Code:
    Call List_Save(List1, "C:\MyFile.txt")
    Oetje
    [email protected]
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  10. #10
    Guest
    Originally posted by oetje
    Originally posted by Stephen Bazemore
    But what would i need to do to save the file with the data in the listbox?
    This function:
    Code:
    Public Sub List_Save(TheList As ListBox, FileName As String)
    On Error Resume Next
    Dim TheContents As String
    Dim fFile As Integer
    fFile = FreeFile
    'this functions overwrites the file
    'so it deletes the file first if it's already there
    If Dir$(FileName) <> "" Then
        'delete the file
        Kill FileName
    End If
    Open FileName For Output As fFile
        For i = 0 To (TheList.ListCount - 1)
            Print #1, TheList.List(i)
        Next
    Close fFile
    End Sub
    Usage:
    Code:
    Call List_Save(List1, "C:\MyFile.txt")

    Oops, didn't see that. And you don't really need this part:

    Code:
    If Dir$(FileName) <> "" Then
        'delete the file
        Kill FileName
    End If
    The reason being is that the Output will automatically overwrite the file no matter what.

    Code:
    Public Sub List_Save(TheList As ListBox, FileName As String)
    On Error Resume Next
    Dim Save As Long
    Dim fFile As Integer
    fFile = FreeFile
    Open FileName For Output As fFile
       For Save = 0 To TheList.ListCount - 1
          Print #fFile, TheList.List(Save)
       Next Save
    Close fFile
    End Sub

  11. #11
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Originally posted by Matthew Gates

    The reason being is that the Output will automatically overwrite the file no matter what.
    I thought that if the file looked like this:
    a
    b
    g
    h
    i
    And then I wrote 3 lines it will look like this:
    1
    2
    3
    h
    i
    Oetje
    [email protected]
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  12. #12
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    No. In keeping with the standard method, Output truncates the file, then begins writing from the beginning. Append opens the file, seeks to the end, and writes from there.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  13. #13

    Thread Starter
    Addicted Member Stephen Bazemore's Avatar
    Join Date
    Aug 2000
    Location
    North Carolina
    Posts
    158
    Thanks for all your help guys. I appreciate it alot.
    Stephen Bazemore
    Email:[email protected]

  14. #14
    Addicted Member Tiovital's Avatar
    Join Date
    Apr 2000
    Posts
    249
    Hi,
    Thnaks For The Info....
    Regards

  15. #15
    Addicted Member Tiovital's Avatar
    Join Date
    Apr 2000
    Posts
    249
    Hi,
    How can i used COLOR in the VB-World Forum? not in html form - somthing like your sample - with a few COLOR?

    Regards



  16. #16
    Guest
    You mean code tags?

    [code]your code[/code]

    Easy, eh?

  17. #17
    Addicted Member Tiovital's Avatar
    Join Date
    Apr 2000
    Posts
    249
    Matthew, Thanks.
    You Are My Hero!!!

    Best Regards

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