Results 1 to 8 of 8

Thread: [RESOLVED] "No error" condition

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    60

    Resolved [RESOLVED] "No error" condition

    I want to enter data into a database, and if I get no errors, I want to put an error box saying the data was added. I don't want to get into a convoluted error handling scheme. Is the abscense of a return code a feasible way of handling this? Any suggestions? Alternatives?

  2. #2
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: "No error" condition

    i think you cannot really avoid complex code especially when you really want to have a full proof code.
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  3. #3
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: "No error" condition

    Not sure I understand your question...

    Why not just use a simple error handler?

    vb Code:
    1. On Error Goto DamnErrors
    2.  
    3. 'Database code here...
    4. Exit Sub
    5.  
    6. DamnErrors:
    7.     Select Case Err.Number
    8.         Case 1234, 308, 302, 999
    9.             Debug.Print "Known error..."
    10.         Case Else
    11.             Debug.Print "Unknown error"
    12.             GiveUp()
    13.             GrabBeer()
    14.             WatchTV()
    15.     End Select

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    60

    Re: "No error" condition

    I can use digirev's suggestion, but I don't really care what the error is. Do I have to list all the errors in order to do a Select? Is there a printable list of all VB error codes someplace?

  5. #5
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: "No error" condition

    why do you need to worry about errors anyway? All you need is a basic On Error Handler without the select case, and just check if there were no errors so you can post the message box.

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: "No error" condition

    How quickly this got away....

    simple error handling at it's minimalist:
    Code:
    On Error Goto errHandler_DB
    
    ' ... do your database stuff
    
    
    'If it gets here, there's no error
    MsgBox "Added!"
    
    resume_Sub:
    Exit Sub/Function/Property/Whatever
    
    errHandler_DB:
      MsgBox "Error #" & cstr(err.Number) & " - " & err.Description
      Resume resume_Sub
    
    End sub/function/property/whaterver
    A "no error" condition is called "normal operation"... meaning nothing goes wrong. IT should follow the normal course of the flow. The only time it should deviate is where there is an error.

    DigiREv came the closest, but complicated by useing the select case... which you only really need to do if you want a specific message for specific errors, or want to do something different based on the errors. But it sounds like in your case, just simply knowing if there was an error (which goes to the error handler) or not (stays within the normal program flow) is enough.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    60

    Re: "No error" condition

    Works like a charm, but I'm not sure if I'm causing a potential problem in closing the connection. Here is the portion of code that is of concern. Do I have a potential problem in exiting the sub before I close the connection?
    Code:
    ...
    strSQL_Insert = "INSERT INTO tblSizes (Dimensions, CupDepth, CupVol, DieArea, CupArea, HobNumber, Shape )"
    strSQL_Insert = strSQL_Insert & " VALUES ('" & strAddToolDimension & "', " & sngAddCupDepth & _
    ", " & sngAddCupVolume & ", " & sngAddDieArea & ", " & sngAddCupSurfaceArea & _
    ", '" & strAddHobNumber & "','" & strAddShape & "')"
    MsgBox "Added!"
    resume_Sub:
        Exit Sub
        
    errHandler_DB:
      MsgBox "Error #" & CStr(Err.Number) & " - " & Err.Description
      Resume resume_Sub
        cn.Execute strSQL_Insert
        cn.Close
        Set cn = Nothing
    End Sub

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED] "No error" condition

    Why are you executing the SQL in the Errorhandler? Especially when it will NEVER execute.

    You're building the SQL, displaying a message box and exiting the sub. There's nothing there to error out, so it will never get to the Erorr Handler. And even if it did, your Resume will jump straight to the exit sub, and NEVER call the cn.Execute, and never will the cn.Close.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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