Following on from the last post ... and ......... some notes based on a discussion here.. http://www.eileenslounge.com/viewtopic.php?f=30&t=31756 .....Lisa Green had noticed something strange in how VBA divides procedures.... some "VB stangeness" .
_.............................
Worded conclusion
Attempting to put into words what is happening, or perhaps more of an attempt at words to fit the situation: ( Generally if I am referring to the sections between procedures, then this can also be taken as valid for the section between a last declaration at the top of a code module and the first procedure )
Scenario 0
The documentation tends to suggest that comments between procedures belong to the procedure below. This would suggest that the dividing line would be immediately below , for example , an End Sub. Indeed this situation is very typically seen. If all in between lines are comments then we see this. Given that the documentation states this, then it could be that something is in place to cause this positioning of the dividing line to behave in this way.
If not all lines are comments, then the situation might not particularly have been thought out and might have been left to chance
If all lines are blank then we see a similar situation: the dividing line would be immediately below , for example , an End Sub. This could be explained by no comments meaning the break point is simply left at immediately below , for example , an End Sub. There is no reason to think that the position as defined so far should be modified in this last situation
That all sound reasonable.
Now consider what might be a reasonable situation of wanting comments immediately below a routine and also wanting comments above a routine. This could be a reasonable requirement: Notes before or after things is a reasonable all day life situation to have.
Further reasonable assumption is that for neatness these 2 sets of comments would be separated for clarity by one or more blank lines. This leads on to
Scenario 1
If we have initially all comment lines, and then make one or more lines blank, then the dividing line “moves down” to the line before the first blank line. We could reasonably interpret this to .. the unbroken comments immediately below the last End as belonging to that last above routine, and a blank line signalising their end.
( Above I am using Empty Line to signalise blank lines - In reality those lines are blank: Scenario1 Explanation.JPG : https://imgur.com/Jzd2nJZ Scenario1 Explanation.JPG )Code:Option Explicit ' '____________________________________________________________________________________________________________________________________________________________________________________________________________________________________ Empty Line ' ' Sub SubAbove() End Sub ' Comments under a sub ' last Comment under a sub____________________________________________________________________________________________________________________________________________________________________________________________________________________________________ Empty Line Empty Line ' First Comment above a Sub ' Comment above a Sub Sub SubBelow() End Sub
Scenarios 2 an 3 general considerations ( Line breaks _ )
We are considering line breaks _ . More specifically in comment lines, ' ____
, since in between procedures or between a procedure
Most things in computing are in, reality, just long strings of characters. If you examine the string that you are able to obtain from the entire contents of a code module ( http://www.excelfox.com/forum/showth...1016#post11016 ) then you find that
_ the long dividing lines across a module don’t seem to be within that string, and
_ the _ used as a line break appears as a normal character without any extra “hidden” characters other than the usually vbCr & vbLf associated with every line.
It is therefore a good assumption that some post processing is responsible for defining the behaviour of the underscore within comments in between procedures
Considering those two _ points above, I think we can further break an attempt to understand what is going on into one,
rather vague guess,
and a
further more reasonable set of explanations
Possibly there is some post processing in place which is designed to recognises a _ at the end of a module code line as linking a code line. Possibly its use in comments between procedures was not particularly considered. This could explain that a by product of this is that, which we observe, whereby a the dividing line never is placed above the line below a break point. In other words , you will never experience that in these two situations, _....
_.. that the dividing line will be placed further up than I have indicated, ( There may be situations where they will be placed further down). An explanation of this could be that the post processing to determining the position of the dividing line may mistake that situation as a code line, and also therefore presume that it is an End type situation:Code:' ' _ '____________________________________________________________________________________________________________________________________ ' Sub Human() ' Poo End Sub ' _ ______________________________________________________________________________________________________________ ' '
If we assume that the above guess for the situation is correct, then scenario2 and scenario 3 , which are the scenarios when a _ is present between procedures, follow on directly from scenario0 and scenario1Code:' ' _This_may_be_mistaken_as_a_code_line_with_a__ '___________break_line_in_it,_and_consequently_this_module_line_may_be_mistaken_as_an_End_procedure_type_line___________________________________________________________________________ ' Sub Human() ' Poo End Sub ' This_may_be_mistaken_as_a_code_line_with_a__ _________break_line_in_it,_and_consequently_this_module_line_may_be_mistaken_as_an_End_procedure_type line____________________________________________________________ ' '
If we assume that the first comment line looking up from a procedure with a trailing _ is as described above, considered as like a _pseudo End Sub__________
'
' _______
‘ _pseudo End Sub __________________________________________________ __________
It then follows,
Scenarion3 = Scenario0 and
Scenarion2 = Scenario1
Scenarion3 = Scenario0
All comment lines or all blank lines below the pseudo End
Scenarrio3.JPG : https://imgur.com/K8fSKrf : Scenarrio3.JPGCode:' ' _ _____pseudo End Sub____________________________________________________________________________________________________ ' ' ' Sub Sconari3() End Sub ' ' _ '_____pseudo End Sub____________________________________________________________________________________________________________ ' ' ' Sub Scenari3() End Sub ' _ '____pseudo End Sub___________________________________________________________________________________ Sub Scenaro3() End Sub ' ' _ ______pseudo End Sub________________________________________________________________________________________________ Sub Sceanrio3() End Sub
So we have the situation that comes close to the simple documentation inferred idea: Comments belong to the procedure below
Scenarion2 = Scenario1
( After the End ( real or pseudo ) not all lines are either all blank or all contain comments)
The first possibility to separate by a blank line is taken looking down from the End :
Scnario 2 .JPG : https://imgur.com/WJF5JAb : Scnario 2 .JPGCode:' Option Explicit ' ' _ pseudo End of declaration section '____Last comment in Declaration section ______________________________________________________________________________________________________________ Sub Subsnario2() End Sub ' ' ' Comments under a sub ' last Comment line _ _______under a sub______pseudo End Sub ______________________________________________________________________________________________________________ ' First Comment above a Sub ' Comment above a Sub ' Sub Ssenario2() End Sub ' ' _ _____pseudo End Sub ______________________________________________________________________________________________________________ ' Sub Sconari2() End Sub ' ' _ ' pseudo End Sub ' '______________________________________________________________________________________________________________ Sub Scenari2() End Sub ' _ '_____pseudo End Sub______________________________________________________________________________________________________________ ' Sub Scenaro2() End Sub ' ' _ ______pseudo End Sub______________________________________________________________________________________________________________ Sub Sceanrio2() End Sub
_.________________________
The next post attempts the briefest summary possible:




Reply With Quote
Bookmarks