Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ben Ben is offline
external usenet poster
 
Posts: 509
Default Run-time error '9' - doesn't occur when unallocated array is Watch

OK, this is one I have no idea about.

Example code as follows:

Sub test()
Dim myArray() As Range
Debug.Print LBound(myArray)
End Sub

1. If I run this sub, I get a run-time error '9' (obviously...).
2. If I step into this sub, I get the same run-time error '9'.
3. If I add a watch to the variable myArray and have it visible in the
Watches window and then run the sub, I get the run-time error '9'.
4. BUT - If I add a watch to the variable myArray and have it visible in the
watches window and then STEP INTO the sub, I DO NOT get the run-time error
'9'. Instead, the value of 0 is output to the Immediate window.

This might seem trivial, but it's proving a bit irritating when I'm trying
to debug a larger project. Also, it's just a puzzler and I'd love to know
what on earth is going on!!!

Thanks to anybody for help.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Run-time error '9' - doesn't occur when unallocated array is Watch

Both debug statments get error 9 below

Sub test()
Dim myArray() As Range
Debug.Print myArray(1)
Debug.Print LBound(myArray)
End Sub

Here we get an error 91

Sub test()
Dim myArray(5) As Range
Debug.Print myArray(1)
End Sub


It appears no memory is assigned to the array until a value is placed in the
array. Adding the watch assigns memory to the array and yu don't get the
error.


"ben" wrote:

OK, this is one I have no idea about.

Example code as follows:

Sub test()
Dim myArray() As Range
Debug.Print LBound(myArray)
End Sub

1. If I run this sub, I get a run-time error '9' (obviously...).
2. If I step into this sub, I get the same run-time error '9'.
3. If I add a watch to the variable myArray and have it visible in the
Watches window and then run the sub, I get the run-time error '9'.
4. BUT - If I add a watch to the variable myArray and have it visible in the
watches window and then STEP INTO the sub, I DO NOT get the run-time error
'9'. Instead, the value of 0 is output to the Immediate window.

This might seem trivial, but it's proving a bit irritating when I'm trying
to debug a larger project. Also, it's just a puzzler and I'd love to know
what on earth is going on!!!

Thanks to anybody for help.

  #3   Report Post  
Posted to microsoft.public.excel.programming
Ben Ben is offline
external usenet poster
 
Posts: 509
Default Run-time error '9' - doesn't occur when unallocated array is W

Think you may be right there. That's one to watch out for, as I was finding
that code was working fine during debugging but was falling over at run-time.

Thanks for your help.

"Joel" wrote:

Both debug statments get error 9 below

Sub test()
Dim myArray() As Range
Debug.Print myArray(1)
Debug.Print LBound(myArray)
End Sub

Here we get an error 91

Sub test()
Dim myArray(5) As Range
Debug.Print myArray(1)
End Sub


It appears no memory is assigned to the array until a value is placed in the
array. Adding the watch assigns memory to the array and yu don't get the
error.


"ben" wrote:

OK, this is one I have no idea about.

Example code as follows:

Sub test()
Dim myArray() As Range
Debug.Print LBound(myArray)
End Sub

1. If I run this sub, I get a run-time error '9' (obviously...).
2. If I step into this sub, I get the same run-time error '9'.
3. If I add a watch to the variable myArray and have it visible in the
Watches window and then run the sub, I get the run-time error '9'.
4. BUT - If I add a watch to the variable myArray and have it visible in the
watches window and then STEP INTO the sub, I DO NOT get the run-time error
'9'. Instead, the value of 0 is output to the Immediate window.

This might seem trivial, but it's proving a bit irritating when I'm trying
to debug a larger project. Also, it's just a puzzler and I'd love to know
what on earth is going on!!!

Thanks to anybody for help.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error occur while loading Sheet1811111111111111111" Help Please! Charles Excel Programming 0 July 8th 08 08:23 PM
Error occur while loading Sheet1811111111111111111" HELP!! Charles Excel Discussion (Misc queries) 0 July 8th 08 08:10 PM
Please help - Looking for a way to sum up for specific error codes that occur in multiple months. Joe Excel Discussion (Misc queries) 4 June 17th 06 04:15 AM
Web query - when does error occur so I can trap it? Matt Lawson[_4_] Excel Programming 1 December 15th 04 08:13 AM
VBA occur error - kernel32.dll Judy[_4_] Excel Programming 1 August 20th 03 10:43 AM


All times are GMT +1. The time now is 12:00 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"