Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Mar 3, 1997

Finding Corresponding EndIf

Question:
I've got ten pages of code and there's an "If" on the first page, a bunch of "If...EndIf" statements throughout the code and the "EndIf" that corresponds with the first "If" lurks somewhere below. Short of just looking for the last "EndIf" (which would work in this case), I'd like to know how to find *any* block closing statement. That is, what's the trick to finding a corresponding "EndIf", "Wend", etc. If the built-in module editor won't cut it I'm open to suggestions for other editors.

Answer:
Unfortunately, there is no easy way to find the closing EndIf (or other keyword) statement. However, good code formatting is often a good solution for this problem. For each If/For/other keywords, indent all of the lines below it. As soon as you add the opening keyword, put in the closing one and add a comment indicating which keyword the end one belongs to, as in this example:

If i > 10 Then
   ... lots of code ...
End If  ' If i > 10 
This should help you find the ends of your loops. The other option, if it is possible, is to break the logical sections into subroutines, into which you pass the necessary variables.
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date