Results 1 to 6 of 6

Thread: Best Load Code - Lol

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Location
    Vb Forums
    Posts
    226

    Talking Best Load Code - Lol

    Ok well im just curious about the load code now and this is what I use at the time:
    VB Code:
    1. On Error GoTo 1
    2.     With CD1
    3.         .DialogTitle = "Open User File"
    4.         .Filter = "All Supported Types|*.usr;*.txt;*.dat|"
    5.         .ShowOpen
    6. Dim sText As String
    7.     Dim x As Integer
    8.     x = FreeFile
    9.     On Error Resume Next
    10.     Open .FileName For Input As #x
    11.     While Not EOF(x)
    12.         Input #x, sText$
    13.             If sText$ = "" Then
    14.             Exit Sub
    15.             Else
    16.             List1.AddItem sText$
    17.             DoEvents
    18.             End If
    19.     Wend
    20.     Close #x
    21.         End With
    22.     Exit Sub
    23. 1
    24. Exit Sub
    Im just looking for advice on what the best load code is and if anything here could be changed to make it better? Thanks guys I appreciate your help
    Thanks For The Help Guys

  2. #2
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    What is this, some god damn game ?

    Its fine.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Location
    Vb Forums
    Posts
    226
    Well no im just using a lot of save and load functions and some people have said its not the ebst code to use so I wanted to ask to see if it was the best so thanks for your help man
    Thanks For The Help Guys

  4. #4
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    if you want best, try leaning toward building your own OS, then you will have much more direct access to the drive.

    really, it's fine
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  5. #5
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456

    Re: Best Load Code - Lol

    Originally posted by _Vb_N00bie_
    Ok well im just curious about the load code now and this is what I use at the time:
    VB Code:
    1. On Error GoTo 1
    2.     With CD1
    3.         .DialogTitle = "Open User File"
    4.         .Filter = "All Supported Types|*.usr;*.txt;*.dat|"
    5.         .ShowOpen
    6. Dim sText As String
    7.     Dim x As Integer
    8.     x = FreeFile
    9.     On Error Resume Next
    10.     Open .FileName For Input As #x
    11.     While Not EOF(x)
    12.         Input #x, sText$
    13.             If sText$ = "" Then
    14.             Exit Sub
    15.             Else
    16.             List1.AddItem sText$
    17.             DoEvents
    18.             End If
    19.     Wend
    20.     Close #x
    21.         End With
    22.     Exit Sub
    23. 1
    24. Exit Sub
    Im just looking for advice on what the best load code is and if anything here could be changed to make it better? Thanks guys I appreciate your help
    Hang on, there is a problem in this code.

    VB Code:
    1. While Not EOF(x)
    2.         Input #x, sText$
    3.             If sText$ = "" Then
    4.             Exit Sub
    5.             Else
    6.             List1.AddItem sText$
    7.             DoEvents
    8.             End If
    9.     Wend

    If sText$ = "" Then
    Exit Sub
    Else

    if text is blank you are exitting the sub. Well, what if there is some blank line in between and there is text after that.

    I mean, lets say text file contains ..

    1
    2
    3

    5

    7

    4
    4
    4


    77

    as soon as it will detect the blank after 3, it will exit the sub. While there is data after that. Isn't it ?

    You should rather say ..

    VB Code:
    1. While Not EOF(x)
    2.         Input #x, sText$
    3.         If trim(sText$) <> "" Then
    4.              List1.AddItem sText$
    5.         End If
    6.         DoEvents
    7.     Wend

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    More standard formatting.
    VB Code:
    1. Dim sText As String
    2.     Dim x As Integer
    3.    
    4.     On Error GoTo ErrorExit
    5.    
    6.     With CD1
    7.         .DialogTitle = "Open User File"
    8.         .Filter = "All Supported Types|*.usr;*.txt;*.dat|"
    9.         .ShowOpen
    10.         x = FreeFile
    11.         On Error Resume Next
    12.         Open .FileName For Input As #x
    13.         While Not EOF(x)
    14.             Input #x, sText$
    15.             If sText$ = "" Then
    16.                 Exit Sub
    17.             Else
    18.                 List1.AddItem sText$
    19.                 DoEvents
    20.             End If
    21.         Wend
    22.         Close #x
    23.     End With
    24.    
    25.     Exit Sub
    26.    
    27. ErrorExit:
    28.  
    29.     Exit Sub
    30.    
    31. End Sub

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