• DJ (unregistered) in reply to MWK

    ExitFunction:
      If Not objConn Is Nothing Then Set objConn = Nothing
      If Not objCmd Is Nothing Then Set objCmd = Nothing
      Exit Function

    HandleError: Dim eNbr$, eSrc$, eDsc$
      eNbr = Err.Number
      eSrc = Err.Source
      eDsc = Err.Description
       
      Err.Raise vbObjectError + eNbr, eSrc, eDsc & " " & strSQL
     
      Resume ExitFunction
    End Function

    <FONT color=#000000>So, he throws an error, bubbles out to the calling function, and then closes the objects... hem.. ;)</FONT>

    <FONT color=#000000>In vb you should ALWAYS set object references to nothing and not let them drop out of scope, there are a number of objects in vb that will be left hanging till the VBIDE is closed if not set to nothing, this doesn't occur when the application is compiled, but can be a real bugger to debug if the compiled app doesn't work as intended, because a reference was decremented ealier than the same call in the VBIDE. </FONT>

    Dj

    <FONT color=#000000></FONT> 

     

  • (cs) in reply to vhawk

    They have to start somewhere!..... :)))))))))))

    I sometimes say... (In business:) "Who does not know, pays! If not does it with the body..."

    If don't know how to do something, you pay to someone to do it for you... if you try to do it.. you shall pay with the body...

    Oh well... isn't properly translated... but that's the idea...

     

    Anonymous:
    :|  Outch !!!   What I enjoy most of all is the amount of extra work and complexity inexperienced programmers can cause themselves

  • (cs)

    You can't say it isn't carefull the SaveApplication false return value, is properly defined even before the variables declaration...

    :)

    Alex Papadimoulis:

    Public Function SaveApplication(ByVal varrApplicationData As Variant) As Variant
      SaveApplication = False
      On Error GoTo HandleError
     
      Dim objConn As ADODB.Connection
      Set objConn = GetConnection()

    (...)

    End Function

Leave a comment on “The Best of Both Worlds”

Log In or post as a guest

Replying to comment #:

« Return to Article