I found on error resume next doesn't work in for each... e.g.
on error resume next
for each x in y
'do stuff
next
if you have an error in for each loop, it falls in infinite loop... it
doesn't move to next element... this sad thing but, it's indication
that we must move to try catch instead of on error.
-Neo 4 3780
It works for me.
'VB 2005
Sub Main()
On Error Resume Next
Dim c As New Collection
c.Add(1)
c.Add(2)
c.Add("A")
c.Add(3)
c.Add("B")
Dim i As Integer
Dim v As Object
i = 0
For Each v In c
i = i + v
Debug.Print(i)
Next
Debug.Print(i)
End Sub
I wrote and tested this code in both VB 6 and 2005. The real issue here is
the use of the On Error Resume Next statement. It should be replaced
whereever feasible with try catch statements.
Mike.
"Neo" <pr*********@gm ail.comwrote in message
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
I found on error resume next doesn't work in for each... e.g.
on error resume next
for each x in y
'do stuff
next
if you have an error in for each loop, it falls in infinite loop... it
doesn't move to next element... this sad thing but, it's indication
that we must move to try catch instead of on error.
-Neo
But does it really raise error? If yes, after error does it move to
next element?
My error was during traversing graphs collection in excel worksheet.The
problem I had when there was an error which made the infinte loop. I am
not sure if that was only to do with that particualar access, bottom
line is say bye, bye to "on error resume next"
Michael D. Ober wrote:
It works for me.
'VB 2005
Sub Main()
On Error Resume Next
Dim c As New Collection
c.Add(1)
c.Add(2)
c.Add("A")
c.Add(3)
c.Add("B")
Dim i As Integer
Dim v As Object
i = 0
For Each v In c
i = i + v
Debug.Print(i)
Next
Debug.Print(i)
End Sub
I wrote and tested this code in both VB 6 and 2005. The real issue here is
the use of the On Error Resume Next statement. It should be replaced
whereever feasible with try catch statements.
Mike.
"Neo" <pr*********@gm ail.comwrote in message
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
I found on error resume next doesn't work in for each... e.g.
on error resume next
for each x in y
'do stuff
next
if you have an error in for each loop, it falls in infinite loop... it
doesn't move to next element... this sad thing but, it's indication
that we must move to try catch instead of on error.
-Neo
Yes, it raises a "First Chance Exception" and then loops to the next item.
I don't know if the Excel Graphs collection is a true COM collection. You
may be better off using
For i as Integer = 0 to Graphs.Count -1
dim gr as Excel.Graph = Graphs(i)
' Do something with gr
next i
Having worked with Excel, I have discovered that some of Excel's collections
are true COM collections and others require using the count method above.
You are correct in that you really need to dump On Error Resume Next. You
should also add "Option Explicit On" and "Option Strict On" at the top of
all your code modules. This will allow the VB compiler to find and flag all
sorts of variable typing errors. You'll be surprised at how many common VB
6 constructs are simply dangerous - Option Strict On will catch 99+% of
them.
Mike.
"Neo" <pr*********@gm ail.comwrote in message
news:11******** **************@ 35g2000cwc.goog legroups.com...
But does it really raise error? If yes, after error does it move to
next element?
My error was during traversing graphs collection in excel worksheet.The
problem I had when there was an error which made the infinte loop. I am
not sure if that was only to do with that particualar access, bottom
line is say bye, bye to "on error resume next"
Michael D. Ober wrote:
It works for me.
'VB 2005
Sub Main()
On Error Resume Next
Dim c As New Collection
c.Add(1)
c.Add(2)
c.Add("A")
c.Add(3)
c.Add("B")
Dim i As Integer
Dim v As Object
i = 0
For Each v In c
i = i + v
Debug.Print(i)
Next
Debug.Print(i)
End Sub
I wrote and tested this code in both VB 6 and 2005. The real issue here
is
the use of the On Error Resume Next statement. It should be replaced
whereever feasible with try catch statements.
Mike.
"Neo" <pr*********@gm ail.comwrote in message
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
I found on error resume next doesn't work in for each... e.g.
>
on error resume next
for each x in y
'do stuff
next
>
if you have an error in for each loop, it falls in infinite loop... it
doesn't move to next element... this sad thing but, it's indication
that we must move to try catch instead of on error.
-Neo
>
Yes, I fully agree with you. I was still usin "on error resume next"
since it was easier. but if it doesnt' work even in one case, shouldn't
be used. Also, once you "on error" you can't use try catch.. that sux.
better not to use "on error".
about option strict and option explicit. I have been always using them.
Thanks for suggesting that, it might be useful to other VB 6 developer
who don't use it.
-Neo
Michael D. Ober wrote:
Yes, it raises a "First Chance Exception" and then loops to the next item.
I don't know if the Excel Graphs collection is a true COM collection. You
may be better off using
For i as Integer = 0 to Graphs.Count -1
dim gr as Excel.Graph = Graphs(i)
' Do something with gr
next i
Having worked with Excel, I have discovered that some of Excel's collections
are true COM collections and others require using the count method above.
You are correct in that you really need to dump On Error Resume Next. You
should also add "Option Explicit On" and "Option Strict On" at the top of
all your code modules. This will allow the VB compiler to find and flag all
sorts of variable typing errors. You'll be surprised at how many common VB
6 constructs are simply dangerous - Option Strict On will catch 99+% of
them.
Mike.
"Neo" <pr*********@gm ail.comwrote in message
news:11******** **************@ 35g2000cwc.goog legroups.com...
But does it really raise error? If yes, after error does it move to
next element?
My error was during traversing graphs collection in excel worksheet.The
problem I had when there was an error which made the infinte loop. I am
not sure if that was only to do with that particualar access, bottom
line is say bye, bye to "on error resume next"
Michael D. Ober wrote:
It works for me.
>
'VB 2005
Sub Main()
On Error Resume Next
Dim c As New Collection
c.Add(1)
c.Add(2)
c.Add("A")
c.Add(3)
c.Add("B")
Dim i As Integer
Dim v As Object
i = 0
For Each v In c
i = i + v
Debug.Print(i)
Next
Debug.Print(i)
End Sub
>
I wrote and tested this code in both VB 6 and 2005. The real issue here
is
the use of the On Error Resume Next statement. It should be replaced
whereever feasible with try catch statements.
>
Mike.
>
"Neo" <pr*********@gm ail.comwrote in message
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
I found on error resume next doesn't work in for each... e.g.
on error resume next
for each x in y
'do stuff
next
if you have an error in for each loop, it falls in infinite loop... it
doesn't move to next element... this sad thing but, it's indication
that we must move to try catch instead of on error.
-Neo
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jason |
last post by:
Is there a way to avoid On Error Resume Next for:
cnn.Open strCon
SQL = "EXEC Customer @txtEmail='" & email_address & "'"
set rs = cnn.execute(SQL)
'On error resume next
rs("email_address")
'// This record does not exist thus throwing up an error. I could use On
|
by: Michael |
last post by:
Hello again everyone,
Hope you can help.
I have a form with a lot of code going on in the background but I
can't find the route cause of the following error message.
Update or Cancel Update Without Add New or Edit.
I understand that when trying to update records you have to work
|
by: deko |
last post by:
I use this convention frequently:
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case 3163
Resume Next
Case 3376
Resume Next
|
by: deko |
last post by:
I want to turn error handling off, then back on in a sub routine that backs
up a select set of documents.
For some reason, I can't seem to get this to work -
Private Sub BackupDocs()
On Error GoTo HandleErr
strBackupDir = "C:\BackupDir"
On Error GoTo 0 ' isn't this supposed to turn off error trapping?
|
by: Squirrel |
last post by:
I have a command button on a subform to delete a record.
The only statement in the subroutine is:
DoCmd.RunCommand acCmdDeleteRecord
The subform's recordsource is "select * from tblVisit order by VisitDt"
I'm getting this error message:
Errno is 2465. Err.description is "Can't find field '|' referred to in your
expression"
| |
by: Anthony England |
last post by:
I am considering general error handling routines and have written a sample
function to look up an ID in a table. The function returns True if it can
find the ID and create a recordset based on that ID, otherwise it returns
false.
**I am not looking for comments on the usefulness of this function - it is
only to demonstrate error handling**
There are three versions of this code. David Fenton says under the earlier
thread "DAO...
|
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 written a sample
function to look up an ID in a table. The function returns True if it can
find the ID and create a recordset based on that ID, otherwise it returns
false.
**I am not looking for comments on the usefulness of this function - it is
|
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 message from
Access. If I comment out the 1st On Error Resume Next and the x = 1 /
0 on the next line there is no difference, i.e. ther same unhandled
error on the same line. I included these 2 lines of code to
demonstrate that On Error Resume Next...
|
by: Maxwell2006 |
last post by:
Hi,
I know that this is not a good practice, but I wonder do we have "on error
resume next" in C#?
Thanks,
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |