Results 1 to 11 of 11

Thread: Coding Question

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517

    Coding Question

    This is a example I was just given.
    Ive seen people do this twice now.

    VB Code:
    1. Private Function FileExists(FullFileName As String) As Boolean
    2. On Error GoTo MakeF
    3. 'If file does Not exist, there will be an Error
    4. Open FullFileName For Input As #1
    5. Close #1
    6. 'no error, file exists
    7. DoExists = True
    8. Exit Function
    9. MakeF:
    10. 'error, file does Not exist
    11. DoExists = False
    12. Exit Function
    13. End Function

    The last 2 lines dont make sense to me...

    Exit function
    End Function

    Why exit the function when its ending anyway???

  2. #2
    It will end itself but it doesn't hurt to throw the Exit Function in there; like in QBasic it was good practice to say END rather than just letting the program execute all lines.

  3. #3
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    id have to agree...its not needed
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    It doesn't matter if you exit or not.
    seoptimizer2001
    VB 6.0, VC++, VI, ASP, JavaScript, HTML,
    Perl, XML, SQL Server 2000

    If God had intended us to drink beer, He would have given us stomachs.


    Please use the [code] and [vbcode] tags in your posts!
    If you don't know how to use them please go HERE!


  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    But then isnt that poor coding.. because your using lines you dont need!

  6. #6
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    id say yes.... wasted space
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  7. #7
    But that's like saying this is bad:
    VB Code:
    1. Dim i As Long
    2. i = 0
    compared to this:
    VB Code:
    1. i = 0
    The performace difference is probably not even an issue. I suppose it's your preference.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    Originally posted by filburt1
    But that's like saying this is bad:
    VB Code:
    1. Dim i As Long
    2. i = 0
    compared to this:
    VB Code:
    1. i = 0
    The performace difference is probably not even an issue. I suppose it's your preference.
    I see that. but that is a good coding standard

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    I see that code as being like this.


    VB Code:
    1. Private Function FileExists(FullFileName As String) As Boolean
    2. dim i
    3. On Error GoTo MakeF
    4. 'If file does Not exist, there will be an Error
    5. Open FullFileName For Input As #1
    6. Close #1
    7. 'no error, file exists
    8. DoExists = True
    9. Exit Function
    10. MakeF:
    11. 'error, file does Not exist
    12. DoExists = False
    13.  
    14. for i = 0 to 5000
    15.     exit function
    16. next
    17. End Function

  10. #10
    Well that's just silly.

  11. #11
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Just to be a chump: Actually your example Filburt isn't the same thing because if you don't dim it as a long then it becomes a variant by default but if you take out the exit then the code is still the same.

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