Results 1 to 12 of 12

Thread: Check if this code is right

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Angry

    I have this code that saves everything in a list box line by line into a file. The compile gives me an error about EOF saying Argument Not Optional!
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Talking

    Sorry forgot the code
    Code:
    Dim ListC As Integer
        Dim ListCi As Integer
        ListC = List1.ListCount + 1
        DoEvents
        For ListCi = 1 To ListC
        Open AccDat.ini For Output As #1
        Do Until EOF
            Print #1, List1.List(ListCi)
        Loop
        Close #1
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  3. #3
    Guest
    Use this code. Makes life easier.

    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
    Hope that helps.

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    you use until eof when reading not writing.
    by the way..did you get the combo box resizing?
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879
    you know where it says listcount - 1, I think that shoudl be + 1. Am i right or wrong.
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Red face To heSaidJoe

    Oh ok, I get yeah. Yes I did get the resizing and found out the problem and fixed it. But here's a question. How do you make it load the list back into the list box when you start the app
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  7. #7
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    wrong
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  8. #8
    Guest
    Actually, isn't it something like:

    Code:
    Dim ListC As Integer
        Dim ListCi As Integer
        ListC = List1.ListCount + 1
        DoEvents
        For ListCi = 1 To ListC
        Open "AccDat.ini" For Output As #1
        Do While Not EOF(1)
            Print #1, List1.List(ListCi)
        Loop
        Close #1

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879
    oh yeah. I remember now. but can you help me with Loading the items back into the listbox when opening the application.
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879
    I need someone's help fast!!!
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  11. #11
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Option Explicit
    
    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
    
    Public Sub List_Load(TheList As ListBox, _
    FileName As String)
    
    On Error Resume Next
    
    Dim Load As Long
    Dim MyVar As String
    Dim fFile As Integer
    fFile = FreeFile
    
    Open FileName For Input As fFile
       Do While Not EOF(fFile)
          Input #fFile, MyVar
          List1.AddItem MyVar
       Loop
      
    Close fFile
    End Sub
    
    'load
    Call List_Load(List1, "C:\My Documents\myfile.txt")
    
    '
    'save
    Call List_Save(List1, "C:\My Documents\myfile.txt")
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879
    Thanx
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


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