Home All Groups Group Topic Archive Search About
Author
29 May 2009 9:34 PM
fred
Hello,
              How to test whether the array is dimmensioned ?
When I do:
        If UBound(SkypeDtmfDelay) > 0 Then

there is an error: "Subscript out of range"

How to test that array SkypeDtmfDelay() without having that error?
Thanks,
Fred

Author
29 May 2009 9:44 PM
Bob Butler
"fred" <fred@nospamme.com> wrote in message
news:eZ9j0UK4JHA.6004@TK2MSFTNGP02.phx.gbl...
> Hello,
>              How to test whether the array is dimmensioned ?
> When I do:
>        If UBound(SkypeDtmfDelay) > 0 Then
>
> there is an error: "Subscript out of range"
>
> How to test that array SkypeDtmfDelay() without having that error?

There are ways but they aren't as clear as just trapping the error or doing
an initial "redim SkypeDtmfDelay(0 to 0)" so that it is always defined.
Author
29 May 2009 11:48 PM
fred
Thank you, Bob.
Initilizing array to 0 ( "redim SkypeDtmfDelay(0 to 0)") is not the solution
for me.
I think, that in that case I need to flag  the situation that array is NOT
redimed by introducing another variable.
Something like this:

Dim ArrayRedim as Boolean
If  ArrayRedim = True then
        If UBound(SkypeDtmfDelay) > 0 Then
==========================

What do you think about that?
Fred

Show quoteHide quote
"Bob Butler" <noway@nospam.ever> wrote in message
news:%232wm%23bK4JHA.4872@TK2MSFTNGP04.phx.gbl...
>
> "fred" <fred@nospamme.com> wrote in message
> news:eZ9j0UK4JHA.6004@TK2MSFTNGP02.phx.gbl...
>> Hello,
>>              How to test whether the array is dimmensioned ?
>> When I do:
>>        If UBound(SkypeDtmfDelay) > 0 Then
>>
>> there is an error: "Subscript out of range"
>>
>> How to test that array SkypeDtmfDelay() without having that error?
>
> There are ways but they aren't as clear as just trapping the error or
> doing an initial "redim SkypeDtmfDelay(0 to 0)" so that it is always
> defined.
>
Author
30 May 2009 12:02 AM
Bob Butler
Show quote Hide quote
"fred" <fred@nospamme.com> wrote in message
news:uXdq$fL4JHA.4632@TK2MSFTNGP02.phx.gbl...
> Thank you, Bob.
> Initilizing array to 0 ( "redim SkypeDtmfDelay(0 to 0)") is not the
> solution for me.
> I think, that in that case I need to flag  the situation that array is NOT
> redimed by introducing another variable.
> Something like this:
>
> Dim ArrayRedim as Boolean
> If  ArrayRedim = True then
>        If UBound(SkypeDtmfDelay) > 0 Then
> ==========================
>
> What do you think about that?

I think trapping the error makes more sense.  Errors and error handling are
not taboo.
Author
30 May 2009 12:54 AM
fred
I have already trapping error in that procedure, however I cannot invoke it
in that case.
The reasons:
1.
I have to continue with the code
2.
Using Resume Next will start the timer which is not desirable if the array
is not redim.
Fred

Show quoteHide quote
"Bob Butler" <noway@nospam.ever> wrote in message
news:uYB$XpL4JHA.140@TK2MSFTNGP03.phx.gbl...
>
> "fred" <fred@nospamme.com> wrote in message
> news:uXdq$fL4JHA.4632@TK2MSFTNGP02.phx.gbl...
>> Thank you, Bob.
>> Initilizing array to 0 ( "redim SkypeDtmfDelay(0 to 0)") is not the
>> solution for me.
>> I think, that in that case I need to flag  the situation that array is
>> NOT redimed by introducing another variable.
>> Something like this:
>>
>> Dim ArrayRedim as Boolean
>> If  ArrayRedim = True then
>>        If UBound(SkypeDtmfDelay) > 0 Then
>> ==========================
>>
>> What do you think about that?
>
> I think trapping the error makes more sense.  Errors and error handling
> are not taboo.
>
Author
30 May 2009 1:05 AM
Bob Butler
"fred" <fred@nospamme.com> wrote in message
news:eBBFjEM4JHA.480@TK2MSFTNGP06.phx.gbl...
>I have already trapping error in that procedure, however I cannot invoke it
>in that case.
> The reasons:
> 1.
> I have to continue with the code
> 2.
> Using Resume Next will start the timer which is not desirable if the array
> is not redim.

neither point makes much sense to me; you can use "resume next", assign the
upper bound to a variable, then restore your original error handler and test
the value.
Author
30 May 2009 1:19 AM
fred
>assign the upper bound to a variable etc
I am not sure if that has any extra advantages fom the "flagging" solution I
showed above.
Fred

Show quoteHide quote
"Bob Butler" <noway@nospam.ever> wrote in message
news:Ou9LeMM4JHA.6004@TK2MSFTNGP02.phx.gbl...
>
> "fred" <fred@nospamme.com> wrote in message
> news:eBBFjEM4JHA.480@TK2MSFTNGP06.phx.gbl...
>>I have already trapping error in that procedure, however I cannot invoke
>>it in that case.
>> The reasons:
>> 1.
>> I have to continue with the code
>> 2.
>> Using Resume Next will start the timer which is not desirable if the
>> array is not redim.
>
> neither point makes much sense to me; you can use "resume next", assign
> the upper bound to a variable, then restore your original error handler
> and test the value.
>
Author
30 May 2009 1:53 AM
MikeD
"fred" <fred@nospamme.com> wrote in message
news:u1LkCTM4JHA.3476@TK2MSFTNGP05.phx.gbl...
> >assign the upper bound to a variable etc
> I am not sure if that has any extra advantages fom the "flagging" solution
> I showed above.


Besides another variable to keep track of?  What happens if just ONE time,
you don't assign True to that variable or if you erase the array you don't
assign False? It introduces "complexity" that you simply don't have to have.
Just trap the error. Why are you so against doing that?

--
Mike
Author
30 May 2009 2:34 AM
fred
You are completely right, Mike.
I have already put my code to work and of course I forgot assign False to my
variable when erasing the array.

I am not sure how to trap the error, but continue with the procedure and NOT
deploying the timer.
Here is the code:
==============
Private Sub moSkype_CallStatus(ByVal pCall As SKYPE4COMLib.ICall, ByVal
Status As SKYPE4COMLib.TCallStatus)
On Error GoTo err_StatusCallback
<more code in here>
        If UBound(SkypeDtmfDelay) > 0 Then
            tmrStartStop.Enabled = False
            tmrStartStop.Interval = SkypeDtmfDelay(1) * 1000
            tmrStartStop.Enabled = True
        End If
<more code in here>
Exit Sub
err_StatusCallback:
    Debug.Print "StatusCallback ==> " & CStr(err.Number) & " : " &
err.Description
    If err.Number = 9 Then Resume Next
End Sub
================
Thanks,
Fred

Show quoteHide quote
"MikeD" <nob***@nowhere.edu> wrote in message
news:e3XRqlM4JHA.140@TK2MSFTNGP03.phx.gbl...
>
> "fred" <fred@nospamme.com> wrote in message
> news:u1LkCTM4JHA.3476@TK2MSFTNGP05.phx.gbl...
>> >assign the upper bound to a variable etc
>> I am not sure if that has any extra advantages fom the "flagging"
>> solution I showed above.
>
>
> Besides another variable to keep track of?  What happens if just ONE time,
> you don't assign True to that variable or if you erase the array you don't
> assign False? It introduces "complexity" that you simply don't have to
> have. Just trap the error. Why are you so against doing that?
>
> --
> Mike
>
Author
30 May 2009 11:56 AM
Larry Serflaten
Show quote Hide quote
"fred" <fred@nospamme.com> wrote

> I am not sure how to trap the error, but continue with the procedure and NOT
> deploying the timer.
> Here is the code:
> ==============
> Private Sub moSkype_CallStatus(ByVal pCall As SKYPE4COMLib.ICall, ByVal
> Status As SKYPE4COMLib.TCallStatus)
> On Error GoTo err_StatusCallback
> <more code in here>
>         If UBound(SkypeDtmfDelay) > 0 Then
>             tmrStartStop.Enabled = False
>             tmrStartStop.Interval = SkypeDtmfDelay(1) * 1000
>             tmrStartStop.Enabled = True
>         End If
> <more code in here>
> Exit Sub
> err_StatusCallback:
>     Debug.Print "StatusCallback ==> " & CStr(err.Number) & " : " &
> err.Description
>     If err.Number = 9 Then Resume Next
> End Sub
> ================

Compare:

   Dim amt as long
> On Error GoTo err_StatusCallback
> <more code in here>
    On Error goTo SkipTimer
    amt = SkypeDtmfDelay(1) * 1000
>  tmrStartStop.Enabled = False
>  tmrStartStop.Interval = amt
>  tmrStartStop.Enabled = True
>  SkipTimer: On Error GoTo err_StatusCallBack
> <more code in here>
> Exit Sub
> err_StatusCallback:
   ... Etc....

If the array assignment fails, it skips over the Timer code and
resets the error target to what it was.  If the assignment succeeds,
the timer is stopped, Interval set, and started again, followed by
resetting the error target back to what it was....

LFS
Author
30 May 2009 5:42 PM
fred
Larry, with that one code you created a big dilemma for me.
Until now I was convinced that the recommended (?) way of placing On Error
statement is to use it only once in the procedure,
but if there is a need to use it again then first should be used On Error Go
To 0 followed by the new error trapping.
The flow I'd expect:
==================
>   Dim amt as long
>> On Error GoTo err_StatusCallback
>> <more code in here>
     On Error goTo 0
>    On Error goTo SkipTimer
>    amt = SkypeDtmfDelay(1) * 1000
>>  tmrStartStop.Enabled = False
>>  tmrStartStop.Interval = amt
>>  tmrStartStop.Enabled = True
>>  SkipTimer:
       On Error goTo 0
       On Error GoTo err_StatusCallBack
>> <more code in here>
>> Exit Sub
>> err_StatusCallback:
>   ... Etc....
=====================
Please comment on that
Thanks,
Fred

Show quoteHide quote
"Larry Serflaten" <serfla***@usinternet.com> wrote in message
news:ePeR41R4JHA.1716@TK2MSFTNGP03.phx.gbl...
>
> "fred" <fred@nospamme.com> wrote
>
>> I am not sure how to trap the error, but continue with the procedure and
>> NOT
>> deploying the timer.
>> Here is the code:
>> ==============
>> Private Sub moSkype_CallStatus(ByVal pCall As SKYPE4COMLib.ICall, ByVal
>> Status As SKYPE4COMLib.TCallStatus)
>> On Error GoTo err_StatusCallback
>> <more code in here>
>>         If UBound(SkypeDtmfDelay) > 0 Then
>>             tmrStartStop.Enabled = False
>>             tmrStartStop.Interval = SkypeDtmfDelay(1) * 1000
>>             tmrStartStop.Enabled = True
>>         End If
>> <more code in here>
>> Exit Sub
>> err_StatusCallback:
>>     Debug.Print "StatusCallback ==> " & CStr(err.Number) & " : " &
>> err.Description
>>     If err.Number = 9 Then Resume Next
>> End Sub
>> ================
>
> Compare:
>
>   Dim amt as long
>> On Error GoTo err_StatusCallback
>> <more code in here>
>    On Error goTo SkipTimer
>    amt = SkypeDtmfDelay(1) * 1000
>>  tmrStartStop.Enabled = False
>>  tmrStartStop.Interval = amt
>>  tmrStartStop.Enabled = True
>>  SkipTimer: On Error GoTo err_StatusCallBack
>> <more code in here>
>> Exit Sub
>> err_StatusCallback:
>   ... Etc....
>
> If the array assignment fails, it skips over the Timer code and
> resets the error target to what it was.  If the assignment succeeds,
> the timer is stopped, Interval set, and started again, followed by
> resetting the error target back to what it was....
>
> LFS
>
>
Author
30 May 2009 11:59 PM
Larry Serflaten
"fred" <fred@nospamme.com> wrote
> Larry, with that one code you created a big dilemma for me.
> Until now I was convinced that the recommended (?) way of placing On Error
> statement is to use it only once in the procedure,
> but if there is a need to use it again then first should be used On Error Go
> To 0 followed by the new error trapping.

I'd suggest that is a bit like setting a variable to 0 before assigning it a different value.
The act of assigning the new value, in effect, replaces the old value whatever it was.

So it is with the error handler.  It can only point to one lable in the procedure.
Re-assigning it to a new label simply replaces the old label, and away you go....

You can disable the error handler before enabling again, if you want, but like setting a
variable to 0 before giving it a new value, its more or less a futile command at that point.

Some might say it is there for readability, and if you agree then leave it in, it isn't going to
hurt anything.  Or, if your intent is to disable the error handler for some amount of code,
then you really would need to use On Error GoTo 0.

But if the very next command after 'GoTo 0' is going to enable the Error handler again,
why bother?

LFS
Author
30 May 2009 1:25 PM
Bob Butler
Show quote Hide quote
"fred" <fred@nospamme.com> wrote in message
news:%234NKl8M4JHA.1808@TK2MSFTNGP06.phx.gbl...
> You are completely right, Mike.
> I have already put my code to work and of course I forgot assign False to
> my variable when erasing the array.
>
> I am not sure how to trap the error, but continue with the procedure and
> NOT deploying the timer.
> Here is the code:
> ==============
> Private Sub moSkype_CallStatus(ByVal pCall As SKYPE4COMLib.ICall, ByVal
> Status As SKYPE4COMLib.TCallStatus)
> On Error GoTo err_StatusCallback
> <more code in here>
>        If UBound(SkypeDtmfDelay) > 0 Then
>            tmrStartStop.Enabled = False

Private Sub moSkype_CallStatus(ByVal pCall As SKYPE4COMLib.ICall, _
       ByVal Status As SKYPE4COMLib.TCallStatus)
Dim lMax As Long
On Error GoTo err_StatusCallback
<more code in here>
On Error Resume Next
lMax=UBound(SkypeDtmfDelay)
On Error GoTo err_StatusCallback
If lMax > 0 Then
   tmrStartStop.Enabled = False
Author
30 May 2009 2:25 AM
mayayana
> I am not sure if that has any extra advantages fom the "flagging" solution
I
> showed above.

  Another option: I usually just start with 1 if
I'm returning an array from a function. So the
return is always an array. Array(0) provides
a handy place to store the ubound or other
data about the array contents, while any returned
data is contained in array(1)+.
Author
30 May 2009 12:06 AM
Ed
On Fri, 29 May 2009 17:34:04 -0400, "fred" <fred@nospamme.com> wrote:

>Hello,
>              How to test whether the array is dimmensioned ?
>When I do:
>        If UBound(SkypeDtmfDelay) > 0 Then
>
>there is an error: "Subscript out of range"
>
>How to test that array SkypeDtmfDelay() without having that error?
>Thanks,
>Fred
>

If (Not SkypeDtmfDelay()) = -1 Then MsgBox "Array Not Dimensioned"
Author
30 May 2009 12:43 AM
Karl E. Peterson
Ed wrote:
> If (Not SkypeDtmfDelay()) = -1 Then MsgBox "Array Not Dimensioned"

I would *absolutely* advise avoiding this one!  It caused me many hours of grief
once, as I tried to track down an Error 0.  Turned out, that was it.
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
30 May 2009 10:37 PM
Ed
On Fri, 29 May 2009 17:43:54 -0700, "Karl E. Peterson" <k***@exmvps.org>
wrote:

>Ed wrote:
>> If (Not SkypeDtmfDelay()) = -1 Then MsgBox "Array Not Dimensioned"
>
>I would *absolutely* advise avoiding this one!  It caused me many hours of grief
>once, as I tried to track down an Error 0.  Turned out, that was it.

Well this is basically how I used it and works just fine,
maybe it doesn't fit the OPs usage?

Private Sub Command1_Click()

  Dim MyArray() As String

'example, code here searches several folders for files with the ".bmp"
file extension, if bmp file(s) found they are added to the array.

  ' did we find any .BMP filenames in the multiple folders?
  If (Not MyArray()) = -1 Then
        Debug.Print "No bmp files found, so do nothing"
    Else
        Debug.Print "Items were add so do something with them here..."
  End If

  ' ..Rest of code here 
End Sub

Cheers,
Ed
Author
1 Jun 2009 11:54 PM
Karl E. Peterson
Ed wrote:
> On Fri, 29 May 2009 17:43:54 -0700, "Karl E. Peterson" <k***@exmvps.org>
> wrote:
>
>>Ed wrote:
>>> If (Not SkypeDtmfDelay()) = -1 Then MsgBox "Array Not Dimensioned"
>>
>>I would *absolutely* advise avoiding this one!  It caused me many hours of grief
>>once, as I tried to track down an Error 0.  Turned out, that was it.
>
> Well this is basically how I used it and works just fine,

I know it can.  I used to use it as well.  Then I started getting a "Runtime Error
0" in the EXE, and couldn't pin it down.  (Try googling that sometime, if you're
really bored.)  It wasn't until I changed this test that the problem went away.
Don't think I'm being superstitious.  This one will come back to bite.
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
2 Jun 2009 5:39 PM
mark.tunnard.jackson
The force is strong in Karl.
Karl is the Yoda of VB6.
Karl says "If use it you do, painful it may be".
I think we should believe him.
Show quoteHide quote
:)
Author
30 May 2009 12:46 AM
fred
That looks like a good solution.
Is it valid in any situations or there are some limitations to it?
Thanks,
Fred

Show quoteHide quote
"Ed" <nospam@hotmail.com> wrote in message
news:52u0259quo25nqfn5mjg4n8g37ok6vj9ho@4ax.com...
> On Fri, 29 May 2009 17:34:04 -0400, "fred" <fred@nospamme.com> wrote:
>
>>Hello,
>>              How to test whether the array is dimmensioned ?
>>When I do:
>>        If UBound(SkypeDtmfDelay) > 0 Then
>>
>>there is an error: "Subscript out of range"
>>
>>How to test that array SkypeDtmfDelay() without having that error?
>>Thanks,
>>Fred
>>
>
> If (Not SkypeDtmfDelay()) = -1 Then MsgBox "Array Not Dimensioned"
>
Author
30 May 2009 1:04 AM
Karl E. Peterson
fred wrote:
> That looks like a good solution.

It is.  Until it's not.  :-(

> Is it valid in any situations or there are some limitations to it?

Some very weird ones.  You'll really, truly wish you'd never seen it, if they bite
you!

If error trapping isn't an option, do this instead:

   Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination
As Any, Source As Any, ByVal Length As Long)

   Public Function ArrayDimmed(vArray As Variant) As Boolean
      Dim pSA As Long
      'Make sure an array was passed in:
      If IsArray(vArray) Then
         'Get the pointer out of the Variant:
         CopyMemory pSA, ByVal VarPtr(vArray) + 8, 4&
         If pSA Then
            'Try to get the descriptor:
            CopyMemory pSA, ByVal pSA, 4
            'Array is initialized only if we got the SAFEARRAY descriptor:
            ArrayDimmed = (pSA <> 0)
         End If
      End If
   End Function

--
..NET: It's About Trust!
http://vfred.mvps.org
Author
30 May 2009 2:39 PM
Rick Rothstein
> Hello,
>              How to test whether the array is dimmensioned ?
> When I do:
>        If UBound(SkypeDtmfDelay) > 0 Then
>
> there is an error: "Subscript out of range"
>
> How to test that array SkypeDtmfDelay() without having that error?

While I would go with the On Error method others have outlined for you, I
just wanted to mention there is an API solution that does not involve using
error trapping...

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
               (pDest As Any, pSrc As Any, ByVal ByteLen As Long)

Function IsInitialized(arr As Variant) As Boolean
   Dim Address As Long, ArrPtr As Long
   CopyMemory ArrPtr, ByVal VarPtr(arr) + 8, ByVal 4
   CopyMemory Address, ByVal ArrPtr, ByVal 4
   IsInitialized = Address <> 0
End Function

Just add the above code to your Form's code window (or put it in a BAS
Module to make it globally available) and call the IsInitialized function
(passing in the array name as the argument) when needed. For example...

Private Sub Command1_Click()
  Dim MyArray() As String
  ' ....
  ' ....  Some code here
  ' ....
  If IsInitialized(MyArray) Then
    '  Do this
  Else
    '  Do that
  End If
  ' ....
  ' ....  Rest of code here
  ' ....
End Sub

--
Rick (MVP - Excel)
Author
30 May 2009 5:06 PM
Nobody
As others suggested, using On Error is normal for testing if an array is
dimmed before, and many other purposes. However, I sense that you prefer to
return error handling back to the default disabled state, so any error in
the IDE would show up. Here is how to do it:

On Error Resume Next
x = UBound(arr)
If Err.Number = 9 Then
    ' Not dimmed
    Exit Function
End If
' Back to normal
On Error GoTo 0

But it's a bad habit not to use error handling. To simplify error handling,
use centralized error handling, see "Centralized Error Handling" on MSDN
Library. Use "Search title only" to find it. Here is the online version:

Centralized Error Handling:
http://msdn.microsoft.com/en-us/library/aa240795(VS.60).aspx

MZTools lets you add error handlers easily, and it's free:

http://www.mztools.com/v3/mztools3.aspx
Author
30 May 2009 6:15 PM
MP
Show quote Hide quote
"Nobody" <nob***@nobody.com> wrote in message
news:%23OeDJkU4JHA.1196@TK2MSFTNGP03.phx.gbl...
> As others suggested, using On Error is normal for testing if an array is
> dimmed before, and many other purposes. However, I sense that you prefer
to
> return error handling back to the default disabled state, so any error in
> the IDE would show up. Here is how to do it:
>
> On Error Resume Next
> x = UBound(arr)
> If Err.Number = 9 Then
>     ' Not dimmed
>     Exit Function
> End If
> ' Back to normal
> On Error GoTo 0
>
> But it's a bad habit not to use error handling. To simplify error
handling,
> use centralized error handling, see "Centralized Error Handling" on MSDN
> Library. Use "Search title only" to find it. Here is the online version:
>
> Centralized Error Handling:
> http://msdn.microsoft.com/en-us/library/aa240795(VS.60).aspx
>
> MZTools lets you add error handlers easily, and it's free:
>
> http://www.mztools.com/v3/mztools3.aspx
>


I've always wondered about GoTo 0
all my procs have an error trap
Sub someProc()
    On Error GoTo someProc_Err

now if i want to use Resume Next for a specific loop or action,
    On Error Resume Next
    '  some anticipated localized error
    If Err then
'    ....
    End if
    On Error GoTo 0 '<<<<<< does this go back to someProc_Err or just
disable error trapping all together?
    ... should i instead of goTo 0 repeat the original direction
    On Error GoTo someProc_Err

thnaks...oops(kind of like snacks but less filling)
mark
Author
31 May 2009 12:41 AM
Henning
Show quote Hide quote
"MP" <Nospam@Thanks.com> skrev i meddelandet
news:OCfcWKV4JHA.4272@TK2MSFTNGP04.phx.gbl...
>
> "Nobody" <nob***@nobody.com> wrote in message
> news:%23OeDJkU4JHA.1196@TK2MSFTNGP03.phx.gbl...
>> As others suggested, using On Error is normal for testing if an array is
>> dimmed before, and many other purposes. However, I sense that you prefer
> to
>> return error handling back to the default disabled state, so any error in
>> the IDE would show up. Here is how to do it:
>>
>> On Error Resume Next
>> x = UBound(arr)
>> If Err.Number = 9 Then
>>     ' Not dimmed
>>     Exit Function
>> End If
>> ' Back to normal
>> On Error GoTo 0
>>
>> But it's a bad habit not to use error handling. To simplify error
> handling,
>> use centralized error handling, see "Centralized Error Handling" on MSDN
>> Library. Use "Search title only" to find it. Here is the online version:
>>
>> Centralized Error Handling:
>> http://msdn.microsoft.com/en-us/library/aa240795(VS.60).aspx
>>
>> MZTools lets you add error handlers easily, and it's free:
>>
>> http://www.mztools.com/v3/mztools3.aspx
>>
>
>
> I've always wondered about GoTo 0
> all my procs have an error trap
> Sub someProc()
>    On Error GoTo someProc_Err
>
> now if i want to use Resume Next for a specific loop or action,
>    On Error Resume Next
>    '  some anticipated localized error
>    If Err then
> '    ....
>    End if
>    On Error GoTo 0 '<<<<<< does this go back to someProc_Err or just
> disable error trapping all together?
>    ... should i instead of goTo 0 repeat the original direction
>    On Error GoTo someProc_Err
>
> thnaks...oops(kind of like snacks but less filling)
> mark
>
>
On Error Goto 0 disables errortrapping.

/Henning
Author
31 May 2009 4:25 AM
Nobody
Show quote Hide quote
"MP" <Nospam@Thanks.com> wrote in message
news:OCfcWKV4JHA.4272@TK2MSFTNGP04.phx.gbl...
> I've always wondered about GoTo 0
> all my procs have an error trap
> Sub someProc()
>    On Error GoTo someProc_Err
>
> now if i want to use Resume Next for a specific loop or action,
>    On Error Resume Next
>    '  some anticipated localized error
>    If Err then
> '    ....
>    End if
>    On Error GoTo 0 '<<<<<< does this go back to someProc_Err or just
> disable error trapping all together?
>    ... should i instead of goTo 0 repeat the original direction
>    On Error GoTo someProc_Err
>
> thnaks...oops(kind of like snacks but less filling)
> mark

You need to use "On Error GoTo someProc_Err" to go back to the previous
error handler. "On Error GoTo 0" returns error handling to the default
disabled state, so if any error happens, the IDE breaks with an error
message and highlighting the line that caused the error as usual.

But rather than commenting out "On Error ..." statements back and forth to
make the IDE show you the errors as if you didn't have error handlers, you
may want to right click the IDE window, and select Toggle-->Break on All
Errors. This basically make VB ignore all "On Error GoTo Label/Resume Next",
so you see all errors as if you didn't have these lines.
Author
31 May 2009 9:28 PM
MP
Thanks
mark

Show quoteHide quote
"Nobody" <nob***@nobody.com> wrote in message
news:O$AyRfa4JHA.5276@TK2MSFTNGP04.phx.gbl...
> "MP" <Nospam@Thanks.com> wrote in message
> news:OCfcWKV4JHA.4272@TK2MSFTNGP04.phx.gbl...
> > I've always wondered about GoTo 0
> > all my procs have an error trap
> > Sub someProc()
> >    On Error GoTo someProc_Err
> >
> You need to use "On Error GoTo someProc_Err" to go back to the previous
> error handler. "On Error GoTo 0" returns error handling to the default
> disabled state, so if any error happens, the IDE breaks with an error
> message and highlighting the line that caused the error as usual.
>
Author
31 May 2009 9:53 PM
MikeD
"Nobody" <nob***@nobody.com> wrote in message
news:O$AyRfa4JHA.5276@TK2MSFTNGP04.phx.gbl...

>
> "On Error GoTo 0" returns error handling to the default disabled state, so
> if any error happens, the IDE breaks with an error message and
> highlighting the line that caused the error as usual.
>

Technically, not quite correct. It disables the *active* error handler in
that procedure, but if another error handler is enabled in a procedure in
the call stack, that error handler then becomes the active error handler.
The IDE will only break if there is no active error handler in the call
stack.  You can have several enabled error handlers, but there can only be
one active error handler at any given time.

So, for example, consider this simple scenario:

Private Sub Form_Load
     On Error GoTo EH

    Call ProcA

    On Error GoTo 0

    <StatementBlock3>

    Exit Sub

EH:

    MsgBox "Error in Form_Load"

End Sub

Private Sub ProcA()

    On Error GoTo EH

    <Statement Block1>

    On Error GoTo 0

    <Statement Block2>

    Exit Sub

EH:

    MsgBox "Error in ProcA"

End Sub

In ProcA, if an error occurs during StatementBlock1, it will be handled by
the error handler in ProcA.  If an error occurs during StatementBlock2, it
will be handled by the error handler in Form_Load which has now become the
active error handler (and the error message is misleading because the error
didn't happen in Form_Load; it was just handled in Form_Load).  If an error
occurs in Form_Load during StatementBlock3, it will not get handled and the
IDE will break (a compiled app will terminate).

--
Mike