473,320 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

on Error GoTo ..... not working properly?

i've been trying to go back through my tutorials and improving their error handling

however something daft is happening.

even when there isnt an error the error handling code is still being run.

say i do this

Expand|Select|Wrap|Line Numbers
  1.  
  2. on Error GoTo Error1
  3.  
  4. 'some other code
  5.  
  6. Error1:
  7.  
  8. MsgBox(" there was an error")
  9.  
  10. End Sub
  11.  
  12.  
so what will happen is, it'll run the code just fine, it'll produce the desired effect and then right at the end it'll pop up the error box even though everythings just worked perfectly.

whats going on?
Nov 1 '07 #1
6 3086
Killer42
8,435 Expert 8TB
Let me ask you a question. If no error occurs, just what do you expect VB to do when it reaches the Error1: label?
Nov 2 '07 #2
i've been trying to go back through my tutorials and improving their error handling

however something daft is happening.

even when there isnt an error the error handling code is still being run.

say i do this

Expand|Select|Wrap|Line Numbers
  1.  
  2. on Error GoTo Error1
  3.  
  4. 'some other code
  5.  
  6. Error1:
  7.  
  8. MsgBox(" there was an error")
  9.  
  10. End Sub
  11.  
  12.  
so what will happen is, it'll run the code just fine, it'll produce the desired effect and then right at the end it'll pop up the error box even though everythings just worked perfectly.

whats going on?


Hi Alexmason86

on error goto is very useful for software programer


here I will give bit of sample
just understand what it has to be used


private sub Test_Error()
on error goto errtrap

here code....


Eixt sub ----here you have to stop program if program is running with out error

errtrap:
if err.number > 0 then
msgbox err.number & space(4) & err.description
Exit sub
end if
End sub


Regards

Prakashsakthivel
Nov 2 '07 #3
debasisdas
8,127 Expert 4TB
What bout Exit Sub before the error label .
Nov 2 '07 #4
What bout Exit Sub before the error label .


Hi

if program runs with out error, it should be out that's why I have written it
otherwise usually it goes to errtrap part..
Nov 2 '07 #5
debasisdas
8,127 Expert 4TB
Hi

if program runs with out error, it should be out that's why I have written it
otherwise usually it goes to errtrap part..
You are correct in your post.
Actually i was replying to the original poster.
Nov 2 '07 #6
Killer42
8,435 Expert 8TB
Thanks guys. :(

I was trying to encourage alexmason86 to think about the structure of the code, rather than just handing out an answer on a silver platter.
Nov 2 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
10
by: Anthony England | last post by:
(sorry for the likely repost, but it is still not showing on my news server and after that much typing, I don't want to lose it) I am considering general error handling routines and have...
3
by: dgiagio | last post by:
Hi, I'm creating a SMTP application and I would like to hear opinions about error handling. Currently there are two functions that communicate with the remote peer: ssize_t...
3
by: bob.needler | last post by:
I know On Error Resume Next is generally considered lazy. But can someone tell me why the resume next in Exit_Handler does not seem to work? It generates the typical unhandled runtime error...
34
by: electrician | last post by:
Perl has it, Basic has it, Fortran has it. What is so difficult about creating a goto command for JavaScript. Just set up a label and say go to it.
1
by: george | last post by:
Hi all, here's my index.asp file. I don't know where has gone wrong. can't run properly, just showing error ASP 0113 Script timeout <!--#include file="head.asp"--> <!-- begin...
8
by: sara | last post by:
I have a report that runs fine with data. If there is no data, I have its NO Data event sending a MsgBox and cancelling the report. Then it seems I still get the 2501 message on the Open Report...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
1
by: resqtech | last post by:
I am having an issue with an Access Database that worked at one time and after a Windows Update that screwed up the profile it stopped working. The following is what VB is stating causes the error. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.