f



Error Handling in VB6 - handler becomes disabled after first error?

I've only been coding in VB for about 5 months, plese excuse this if
it's elementary.

I'm creating a program in VB6 which will go through the list of
customer accounts in our SQL-2000 database and do some cleanup. For a
few hundred of our subcontracted accounts, the USPS ZipFour database
for that block of zip codes and street segments hasn't been imported
to our database, these accounts cause errors in my program and need to
be skipped.

I've created an Error handler which is supposed to jump to the end of
the loop for my ADODB recordset. It works fine the first time, the
error clears and the program continues looping through the recordset.
On the second account, however, the program seems to ignore the On
Error statement and comes crashing to a halt with the run-time
messagebox.

>SNIP<
        
        
        sZipCode = rsAcct("ServiceZip") & ""
        
        sSQL = "SELECT PrimLowAddress, PrimHighAddress, CarrierRt,
PrimEOB, streetPreDirection, " & _
                "StreetPostDirection FROM [" & sTable & "] A " & _
                "WHERE A.StreetName = '" & sStreetName & "' AND
A.ZipCode = '" & sZipCode & "' " & _
                "ORDER BY PrimLowAddress, PrimHighAddress;"
                
        'for records where Zip code table is not in database
        If sTable = "596" Then
        StrError = "***Zip code not in database " & sTable
            GoTo invalidName
        End If
        If IsNull(rsAcct!servicezip) = True Then
            StrError = "No Zip code"
            GoTo invalidZip
        End If       
        For intCheck = 1 To Len(sStreetName)
            If Mid(sStreetName, intCheck, 1) = Chr(39) Then
            StrError = "Apostrophe in name"
            GoTo invalidName
            End If
        Next
'CODE CRASHES HERE (ON RECORDSET OPEN)              
        rsZip.Open sSQL, cn, adOpenStatic, adLockReadOnly
        intMatch = 0
        If Not rsZip.EOF Then
            rsZip.MoveLast
            rsZip.MoveFirst
        End If
        'check Even/Odd/Both status, if both then count by one else
count by two
        Do Until rsZip.EOF

>SNIP SNIP<


invalidZip:
        StrError = ""
        If intMatch = 1 Then intMatchCount = intMatchCount + 1
        rsAcct.MoveNext
    Loop
    
    lblLabel.Caption = "FINISHED." & "Found " & intMatchCount & "
entries out of " & rsAcct.RecordCount
  
        
    'release recordsets from memory
    Set rsZip = Nothing
    Set rsAcct = Nothing
    Set cn = Nothing
Exit Sub

ErrorHandling:
    Debug.Print "Error " & Err.Number & "   " & Err.Description
    Select Case Err.Number
        Case -2147217865 'Object not found (ZIP code table not in
database)
            Debug.Print "Zip prefix " & sZipCode & " is not loaded in
the database. Record will be skipped."
            Err.Clear
            GoTo invalidZip
    End Select
    
End Sub
0
andreranieri
6/27/2003 10:56:12 PM
comp.basic.visual.database 1601 articles. 0 followers. Post Follow

1 Replies
529 Views

Similar Articles

[PageSpeed] 59

"Andre" <andreranieri@hotmail.com> wrote in message <news:87a2cf3f.0306271456.5be3040a@posting.google.com>...

> I've only been coding in VB for about 5 months, plese excuse this if
> it's elementary.
>
> I'm creating a program in VB6 which will go through the list of
> customer accounts in our SQL-2000 database and do some cleanup. For a
> few hundred of our subcontracted accounts, the USPS ZipFour database
> for that block of zip codes and street segments hasn't been imported
> to our database, these accounts cause errors in my program and need to
> be skipped.
>
> I've created an Error handler which is supposed to jump to the end of
> the loop for my ADODB recordset. It works fine the first time, the
> error clears and the program continues looping through the recordset.
> On the second account, however, the program seems to ignore the On
> Error statement and comes crashing to a halt with the run-time
> messagebox.

You're exiting the error handler with a GoTo, when you need to
use Resume.  Without seeing the rest of your code, I can't tell
if your use of GoTos is really the best strategy or not.  Most
will tell you that GoTo is evil, but sometimes GoTo just sucks
less than the alternatives.

> >SNIP<
>
>
>         sZipCode = rsAcct("ServiceZip") & ""
>
>         sSQL = "SELECT PrimLowAddress, PrimHighAddress, CarrierRt,
> PrimEOB, streetPreDirection, " & _
>                 "StreetPostDirection FROM [" & sTable & "] A " & _
>                 "WHERE A.StreetName = '" & sStreetName & "' AND
> A.ZipCode = '" & sZipCode & "' " & _
>                 "ORDER BY PrimLowAddress, PrimHighAddress;"
>
>         'for records where Zip code table is not in database
>         If sTable = "596" Then
>         StrError = "***Zip code not in database " & sTable
>             GoTo invalidName
>         End If
>         If IsNull(rsAcct!servicezip) = True Then
>             StrError = "No Zip code"
>             GoTo invalidZip
>         End If

>         For intCheck = 1 To Len(sStreetName)
>             If Mid(sStreetName, intCheck, 1) = Chr(39) Then
>             StrError = "Apostrophe in name"
>             GoTo invalidName
>             End If
>         Next

You should be able to replace this entire loop with just,
          If InStr(1, sStreetName, "'", vbBinaryCompare) > 0 Then
              StrError = ... etc etc etc

> 'CODE CRASHES HERE (ON RECORDSET OPEN)
>         rsZip.Open sSQL, cn, adOpenStatic, adLockReadOnly
>         intMatch = 0

>         If Not rsZip.EOF Then
>             rsZip.MoveLast
>             rsZip.MoveFirst
>         End If

The above shouldn't be needed if you're just going to iterate
through the records anyway.

>         'check Even/Odd/Both status, if both then count by one else
> count by two
>         Do Until rsZip.EOF
>
> >SNIP SNIP<
>
>
> invalidZip:
>         StrError = ""
>         If intMatch = 1 Then intMatchCount = intMatchCount + 1
>         rsAcct.MoveNext
>     Loop
>
>     lblLabel.Caption = "FINISHED." & "Found " & intMatchCount & "
> entries out of " & rsAcct.RecordCount
>
>
>     'release recordsets from memory
>     Set rsZip = Nothing
>     Set rsAcct = Nothing
>     Set cn = Nothing
> Exit Sub
>
> ErrorHandling:
>     Debug.Print "Error " & Err.Number & "   " & Err.Description
>     Select Case Err.Number
>         Case -2147217865 'Object not found (ZIP code table not in
> database)
>             Debug.Print "Zip prefix " & sZipCode & " is not loaded in
> the database. Record will be skipped."
>             Err.Clear
>             GoTo invalidZip
>     End Select
>
> End Sub

--
Joe Foster <mailto:jlfoster%40znet.com>     Got Thetans? <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!


0
Joe
6/27/2003 11:38:31 PM
Reply:

Similar Artilces:

Robust error handling, an error while handling another error
I've been having this discussion a lot with my colleagues at work. A buffered file writer is the classic example. #include <fstream> int main() { std::ofstream fout("foo.txt"); if ( ! fout) return 1; //write important data to file //let the destructor implicitly close the file handle } The ofstream destructor will call flush then free the file handle, return it to the operating system. However, flush can fail. The disk can be full, for example. When flush fails, it sets a state flag, but there is no opportunity for the user to examine this state fl...

Testing Error Handling for Unusual Database Errors
Have you ever had a piece of database code in which you wanted to test every probable and improbable error condition that might occur? For example, suppose you had this code and wanted to make sure that the error handling did the right thing when an InstantiationException occurred: ---------------------------------------------------------------------------------------------------------------- /* Load the JDBC driver. */ try { Class.forName(this.jdbcDriverName).newInstance(); } catch (ClassNotFoundException cnf_excp) { String msg = &quo...

When is an error not an error?
The Java language specification claims in: 8.8.7.1 Explicit Constructor Invocations .... "If an anonymous class instance creation expression appears within an explicit constructor invocation statement, then the anonymous class may not refer to any of the enclosing instances of the class whose constructor is being invoked." Helpfully it gives an example: "For example: class Top { int x; class Dummy { Dummy(Object o) {} } class Inside extends Dummy { Inside() { super(new Object() { int r = x; }); // err...

Error in Visual Basic closes the database
Hello, I am working in a new form and still making changes to the visual basic code of the form. Not always, but very often when I try to save my changes in the visual basic window and press the icon, this window closes(without saving) and the whole database, too. I already tried to switch everything in a new form and error occurs again after starting to work in the visual basic code of this specific form not in others and I did compile and repair the db, too. I would appreciate any other ideas. Thanks Nicole Did you try a decompile? This sequence should work: 1. Uncheck the boxes under...

error or not an error ...
I was just testing out the R4 REXX thingy, and it found an error in the following program. My question is this, is it an error or not? My PC/REXX and Regina don't barf on it, but I thought they should've. _____________________________________________ /**/ ?.='' ?.z='batman' trace i if ?.z\==''then do; say '?.z=' ?.z; end ______________________________________________ Note that there is space before the THEN. I'm not sure of the exact rules for parsing an IF statement, I know that THEN is a "reserved" keyword when an IF statement is...

When is an error not an error?
When it's OSS slopware, of course. http://www.angelfire.com/planet/dfs0/Knode_send_error.png On 2006-09-12 02:42, * DFS wrote: > When it's OSS slopware, of course. > > http://www.angelfire.com/planet/dfs0/Knode_send_error.png > Well, some time ago I had a problem with OE - too long reference line to other posts, and OE of course refused to send... then crashed. Should I name it a feature? -- Andrea On Tue, 12 Sep 2006 03:25:29 +0200, Andrea wrote: > On 2006-09-12 02:42, * DFS wrote: >> When it's OSS slopware, of course. >> >> http:/...

error in error code database
Hi, &nbsp; I have this error (screenshot provided), which problem is its asking for a password. I think this vi is ni developed. So,&nbsp;I have tried to reinstall labview but still this cannot work. Thanks, for any help. &nbsp; Best regards, Edwin &nbsp; error_code_database_password.zip: http://forums.ni.com/attachments/ni/170/130546/1/error_code_database_password.zip Hi Edwin, The error is most likely caused by opening an LLB in a newer version of LabVIEW than the version it was developed on. It is commonly seen with the "Error Code Database.vi" when upgrading f...

Error Visual Basic: ! Compile error. Can't find project or library
Hi all, When running a program I made in VB under Windows XP i'm getting the following error: ! Compile error. Can't find project or library. (see also http://home.kabelfoon.nl/~hspies/2.jpg ) See the code where it stucks: http://home.kabelfoon.nl/~hspies/1.jpg Ubder Windows 98 this error does not occur. Who knows what I do wrong, I've tried a lot but the error keeps coming in Win XP. Thanks. John Check what "TextString" is declared as. If it is not declared - declare it as String. "Familie Spies" <hspies@caiw.nl> wrote in message news:411d0ace$...

Objc Nubie: Errors Errors Errors
I've been toying with learning ObjC/Cocoa for sometime and finally got over the hump of "brackets vs. braces" but am wondering why my little test throws so many warnings when run: // gcc FileTest.m -o FileTest -ObjC -framework Cocoa #include <Cocoa/Cocoa.h> #include <Foundation/Foundation.h> int main( void ) { NSString * str = [ [NSStringalloc] initWithString:@"~/samplefromcocoa.txt" ]; NSString * full = [ NSString stringWithString: [str stringByExpandingTildeInPath ] ]; if( [ [NSFileManager defaultManager] fileExistsAtP...

Error in error code database.vi
Hi.... I am working on a programm which was developed in Version 6.1. I am currently working with Version 7.1 and I get the errors in the following VI; -General Error Handler -Error Code Database General Error Handler CORE I've been trying to solve my problem with the following posts; http://digital.ni.com/public.nsf/websearch/A87185BF42937DE986256CB0006CA387= ?OpenDocument http://groups.google.de/group/comp.lang.labview/browse_thread/thread/fb2c52= fd4f089517/75d7b00ac66509fb?q=3Derror+code+database&rnum=3D1#75d7b00ac66509= fb It did work the first time after Reinstalling Version ...

Understanding error masking in error handling...
Hey all :) I was wondering about the $error_types (I particularly notice the 's' suffix when reading the manual) parameter for 'set_error_handler()': Can be used to mask the triggering of the error_handler function just like the error_reporting ini setting controls which errors are shown. Without this mask set the error_handler will be called for every error regardless to the setting of the error_reporting setting. And, in my php.ini I have, error_reporting = E_ALL & ~E_NOTICE Which - I think - means something like "E_ALL and less severe AND NOT E_NOTICE in pa...

visual basic error
I have a problem, it's not with any code I have because... there is no code. When I run a blank visual basic 6 form, it opens up just fine. When I add a text box, a caption, and a button... it gives me an error from microsoft's error report and asks me to send or not send the error, i chose and then it quits. The error report won't let me copy the data, but i gather it's pretty useless information unless you have the source code to visual basic. I get this often when I install visual studio and often a reinstall of windows and visual basic would fix it. I assume it's a pret...

Error Directing BCP In Errors to error file
Greetings, I am trying to bcp in data to a table which is in different server. Though the bcp in works fine but the error file is not being created and rejected records are not being directyd to the error file. Query looks like: bcp <db>..test_b_plan_cp in /home/file_out.txt -c -t '|' -S *****-U ****** -P ******-I /home/bcp2db_sql.ini -e /home/bcp2db.error. Can someone please help? TIA. Regards, Rajpreet ...

error C2106: error C2057 :error C3304:
I have faced intrinsic errors "error C2106 / error C2057 / error C3304" in Visual studio 2008. Though the source files have included with header files like "math.h" and "ctype.h", compilation gives error as given below. 2>c:\apps\microsoft visual studio 9.0\vc\include\string.h(48) : error C2106: '=' : left operand must be l-value 2>c:\apps\microsoft visual studio 9.0\vc\include\string.h(48) : error C2057: expected constant expression 2>c:\apps\microsoft visual studio 9.0\vc\include\string.h(48) : error C3304: 'PreAttribute': at...

Error directing BCP In errors to error file
Greetings, I am trying to bcp in data to a table which is in different server . Though the bcp in works fine but the error file is not being created and rejected records are not being directyd to the error file. Query looks like: bcp <db>..test_b_plan_cp in /home/file_out.txt -c -t '|' -S *****-U ****** -P ******-I /home/bcp2db_sql.ini -e /home/bcp2db.error. Can someone please help? TIA. Regards, Rajpreet ...

Web resources about - Error Handling in VB6 - handler becomes disabled after first error? - comp.basic.visual.database

Automobile handling - Wikipedia, the free encyclopedia
Automobile handling and vehicle handling are descriptions of the way wheeled vehicles perform transverse to their direction of motion, particularly ...

New Facebook SDK For IOS Adds Automatic Error Handling, Improved Login UI
... software-development kit for iOS is now available for download , with significant enhancements including a beta test of automatic error handling ...

Handling Disputes and Refunds
Handling Disputes and Refunds

Facebook Shares Stats on How Users are Handling the Latest Privacy Changes
Facebook’s traffic has yet to be affected by the aggressive privacy changes it made at the beginning of December, from what data we can see — ...

Handling five billion sessi
... into their mobile apps. Skip to main content Engineering Blog Have an account? Sign in Search form Search All Twitter Blogs &nbsp Handling five ...

Customer Service Handling
This group is for people in customer service profession facing the customer either in person or over phone.

Avocado Meal Planner - Meal planning, recipe handling and grocery shopping made easy on the App Store ...
Get Avocado Meal Planner - Meal planning, recipe handling and grocery shopping made easy on the App Store. See screenshots and ratings, and read ...

Vintage Ad #964: Students deserve Special Handling at Bob Jones University - Flickr - Photo Sharing!
I recently acquired a large number of Christian lifestyle magazines from the 60s and 70s. This ad features an institution that has tended to ...

How to Fly the P-47: Ground Handling, Take-Off, Normal Flight, Landing - 1943 - WDTVLIVE42 - YouTube
Demonstrates procedures in flying the P-47. Includes preflight and cockpit checks, warm-up, taxiing, cruising, banking, stalling, speeds for ...

34% Rate Obama’s Handling of Government Spending As Good or Excellent
Voters continue to question President Obama's handling of issues related to government spending and taxes. A new Rasmussen Reports national telephone ...

Resources last updated: 1/28/2016 4:00:43 AM