Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / July 2008

Tip: Looking for answers? Try searching our database.

Run-time error '9' - doesn't occur when unallocated array is Watch

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ben - 31 Jul 2008 05:03 GMT
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.
Joel - 31 Jul 2008 13:06 GMT
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.

> OK, this is one I have no idea about.
>
[quoted text clipped - 18 lines]
>
> Thanks to anybody for help.
ben - 01 Aug 2008 00:35 GMT
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.

> Both debug statments get error 9 below
>
[quoted text clipped - 37 lines]
> >
> > Thanks to anybody for help.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.