Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Ifs, Selects & Loops Error Statements
Currently, if you have a macro which contains a number of "closed"
statements, such as IF, SELECT CASE, DO...LOOP etc, the VBA error-detection system tends to be a little random in its identification of where the error lies if one or more of the statements aren't closed. e.g. if you have three "Select Case" statements within an "IF", and one of the "Select Case" isn't closed with an "End Select" - VBA will frequently tell you that there is an "Block If without End If", rather than a "Block Select without End Select" which would make things easier to locate the bug in question. Especially as, when you hit "debug" to the error, the highlighted area is the mistaken location rather than the actual error area. e.g.: Sub Whatever() hrng = 1 If 1 0 Then Select Case hrng Case 1 MsgBox "Yo!" Case 2 MsgBox "uh-huh" Case 3 MsgBox "Whoa!" End If End Sub In this instance, the Select is not closed. When attempting to run, however, the error message received is an "End If Without Block If" Compile Error, and the "End If" is higlighted, rather than the "Select" which is not closed. Obviously, the example above is very basic, but this would prove very useful when there are hundreds upon hundreds of lines of code containing multiple closed statements, and the current process reduces me to a wreck trawling through line by line looking for an unclosed statement! or I could just learn to always close, but that would be far too easy.... =:-) ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/office/comm...el.programming |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
ADO & Loops: error in code? | Excel Programming | |||
On Error and Loops | Excel Programming | |||
loops and if statements | Excel Programming | |||
loops and if statements | Excel Programming | |||
Error Handling and For-Next Loops | Excel Programming |