VB> Strangeness

LisaGreen
5StarLounger
Posts: 964
Joined: 08 Nov 2012, 17:54

VB> Strangeness

Post by LisaGreen »

Hello everyone,

I've come across something weird in the VBE.

In the picture, You can see that the thin line inserted at the end of procedures by the VBE isn't in the correct place. I also have a procedure to insert moduke line numbers in a procedure and you can see that VBA thinks the end of the procedure is at line 389 instead of 385.

Can anyone explain this please?

TIA
Lisa
Prob 1.PNG
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78485
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VB> Strangeness

Post by HansV »

It looks like a bug. Apparently a multi-line function/sub declaration that is commented out confuses the VBE.
Best wishes,
Hans

LisaGreen
5StarLounger
Posts: 964
Joined: 08 Nov 2012, 17:54

Re: VB> Strangeness

Post by LisaGreen »

Thank you Hans.

It's a bit worrying in some ways... I thought the VBE was perfect!!! LOL!!!!

Thank you again!

I think I'm going to test some more to confirm that and try to account for it.

Is there anywhere we can post/send/make people aware... of "bugs" like this do you know?? Though I doubt it will get acted on... :-(

Actually, do you know of any source that lists "bugs" in the VBE at all Hans??

And thank you for relieving my paranoia!!!

TIA yet again!!!
Lisa

User avatar
HansV
Administrator
Posts: 78485
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VB> Strangeness

Post by HansV »

If you have a recent version of Office, you can use File > Feedback > Send a Frown to report it to Microsoft.
I agree that it is unlikely that Microsoft will correct it.
Best wishes,
Hans

User avatar
StuartR
Administrator
Posts: 12605
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: VB> Strangeness

Post by StuartR »

It's hard to argue that you are right and Microsoft is wrong. The lines in question are comments that come after one function and before the next. How is VBA supposed to know which function these comments belong to?
StuartR


User avatar
HansV
Administrator
Posts: 78485
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VB> Strangeness

Post by HansV »

The behavior is a bit strange:
S2518.png
If the commented out Sub statement of Sub2 is a single line, the dividing line is above that statement, i.e. all comments are considered to belong to the Sub below.
If, on the other hand, it consists of multiple lines (with continuation characters _), the dividing line is below that statement. That doesn't seem logical to me.
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

User avatar
StuartR
Administrator
Posts: 12605
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: VB> Strangeness

Post by StuartR »

Maybe it isn't logical, but it isn't wrong either
StuartR


User avatar
HansV
Administrator
Posts: 78485
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VB> Strangeness

Post by HansV »

OK...
Best wishes,
Hans

LisaGreen
5StarLounger
Posts: 964
Joined: 08 Nov 2012, 17:54

Re: VB> Strangeness

Post by LisaGreen »

Can you explain please why you don't think it's wrong Stuart??

Lisa

LisaGreen
5StarLounger
Posts: 964
Joined: 08 Nov 2012, 17:54

Re: VB> Strangeness

Post by LisaGreen »

Hello,

I don't have VB. Can anyone who has check whether VB has the same behaviour as VBA for this please?

User avatar
Doc.AElstein
BronzeLounger
Posts: 1499
Joined: 28 Feb 2015, 13:11
Location: Hof, Bayern, Germany

Re: VB> Strangeness

Post by Doc.AElstein »

Hi Lisa, Hans, Stuart,

I think sometimes, one man’s Bug is another man’s “feature”, especially when the other man is a computer programmer. Programmers, I have learnt, do not do things wrong, they may sometimes do different versions or updates things, ( for better and for worse).
_._____________________

One possible explanation of how the thing has been written … probably wrong , but it fits, so it will do as a Theory until someone tells us the correct one…

Ignoring, for now, the last procedure, which may be handled a bit differently…. Consider for now just procedures within a code module

It appears to me, at least for now, that the end of the last procedure may be determined by
Either
A blank line
Or
An End

In the case of VBA looking for a blank line..... it might look for something related to one of the different ways used in a long computer strings to indicate to make a new line. ( The entire coding in a code module like many things in computing is just a long string )
So maybe when VBA “goes a lookin” for where to make the end , it meets its criteria as written by the programmer, when it hits one of those line continuation things _

As a demo, in this set of coding, VBA may recognise the _ in this line
by one of the various things _
as what it is programmed to look for when it “goes a lookin” for an end

Put another way,… The criteria looked for in between procedures to determine the last end, is met in the case of an End, a blank line, or a situation as shown involving one of those _

I am assuming in my Theory that VBA looks backwards, as it often seems to….
_ ._______________

I had not noticed this feature before. For me it could be very useful as I have another way to organise my 'Green comments.
Thanks for noticing and bringing it up Lisa… Now ya got more to write about in ya Book !!! :-)

WheresMeEndGone.JPG : https://imgur.com/wDwTKT0" onclick="window.open(this.href);return false;
WheresMeEndGone.JPG
( If you copy this coding below, don't forget the last sub routine, right at the bottom )

Code: Select all

 Option Explicit '    http://www.eileenslounge.com/viewtopic.php?f=30&t=31756
Public Ludwig As Legend
Dim VBIDEVBAProj As Object:
'

'
'
Sub Last_End_Determined_By_A_Blank() ' This has 7 lines in it
 Set VBIDEVBAProj = ThisWorkbook.VBProject.VBE.ActiveCodePane.CodeModule
 Debug.Print VBIDEVBAProj.ProcCountLines("Last_End_Determined_By_A_Blank", 0) & "   " & VBIDEVBAProj.CountOfLines
End Sub
'
Sub Last_End_Determined_By_A_End()  '  This has 8 lines in it
 Set VBIDEVBAProj = ThisWorkbook.VBProject.VBE.ActiveCodePane.CodeModule
 Debug.Print VBIDEVBAProj.ProcCountLines("Last_End_Determined_By_A_End", 0) & "   " & VBIDEVBAProj.CountOfLines
End Sub
' Maybe the Blank is determine _
   by one of the various things _
    used to make a "carriage return/ New line thingy"
'
'
'
'
'
Sub Foops()
Set VBIDEVBAProj = ThisWorkbook.VBProject.VBE.ActiveCodePane.CodeModule
 VBIDEVBAProj.InsertLines Line:=VBIDEVBAProj.CountOfLines + 234, String:="'Line " & VBIDEVBAProj.CountOfLines + 1
 Debug.Print VBIDEVBAProj.ProcCountLines("Foops", 0) & "   " & VBIDEVBAProj.CountOfLines
End Sub
'
' Next space determines that this is the end of this routine




'

'



































Sub Hello_Who_Ever_Got_This_Far()

End Sub


Edit….. just to possibly make it a little clearer what I am talking about … a “blank” line is only blank to us. There is something there related to something to do with making a line.
Consider these 3 things:
_1 A normal line with stuff in it,
_2 a “blank” line ,
_3 a line caused by a _ continuation thing
These three will likely be handled differently, particularly _1 and _3 , as it is important to distinguish between them.
But there may be some similarity in _2 and _3 which is that thing which VBA looks for when it is looking for where to draw that line across to separate coding sections…..
You do not have the required permissions to view the files attached to this post.
Last edited by Doc.AElstein on 04 Feb 2019, 16:43, edited 6 times in total.
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also

User avatar
StuartR
Administrator
Posts: 12605
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: VB> Strangeness

Post by StuartR »

LisaGreen wrote:Can you explain please why you don't think it's wrong Stuart??

Lisa
One function ends. Then there are some comments. Then another function starts.
The comments are not part of either function.
The line between functions could be displayed at any point after one ends and before the other begins.
StuartR


User avatar
Doc.AElstein
BronzeLounger
Posts: 1499
Joined: 28 Feb 2015, 13:11
Location: Hof, Bayern, Germany

Re: VB> Strangeness

Post by Doc.AElstein »

LisaGreen wrote:I don't have VB. Can anyone who has check whether VB has the same behaviour as VBA for this please?
In my Visual Basic 2008, line continuation things are not allowed.
In my Visual Basic 2010, the end of routines is always shown as at the End and the start of the routine in shown as at the start. Anything in between, such as commented lines, is shown as a separate section. So it appears, at first glance, that in my Visual basic 2010 comment lines are not part of a routine. But i have not done any coding in VB 2008 or VB 2010 to see what the coding suggests when asked about line numbers and stuff
Last edited by Doc.AElstein on 04 Feb 2019, 15:20, edited 1 time in total.
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also

User avatar
Doc.AElstein
BronzeLounger
Posts: 1499
Joined: 28 Feb 2015, 13:11
Location: Hof, Bayern, Germany

Re: VB> Strangeness

Post by Doc.AElstein »

StuartR wrote:[
One function ends. Then there are some comments. Then another function starts.
The comments are not part of either function.
The line between functions could be displayed at any point after one ends and before the other begins.
The numbers chucked up in the demo coding in my post suggest that VBA is somehow attributing the comments to a routine. ( I have not checked with Functions yet ) The way it looks with the separating lines suggests that as well.
But I suppose it is academic and open to interpretation as to whether they belong to the routines or are outside them ..
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also

LisaGreen
5StarLounger
Posts: 964
Joined: 08 Nov 2012, 17:54

Re: VB> Strangeness

Post by LisaGreen »

StuartR wrote:
LisaGreen wrote:Can you explain please why you don't think it's wrong Stuart??

Lisa
One function ends. Then there are some comments. Then another function starts.
The comments are not part of either function.
The line between functions could be displayed at any point after one ends and before the other begins.
My experience is that comments between procedures belong to the procedure below them. This seems to be born out by the extenibility functions ProcOfLine, ProcBodyLine, ProcStartLine, and ProcCountLines. I believe it is also mentioned in their documentation from microsoft.

https://docs.microsoft.com/en-us/office ... countlines
The ProcCountLines property returns the number of lines in a procedure, beginning with the line returned by the ProcStartLine property and ending with the line that ends the procedure. The procedure may be ended with End Sub, End Function, or End Property.
Lisa

User avatar
StuartR
Administrator
Posts: 12605
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: VB> Strangeness

Post by StuartR »

Yes, Lisa, I agree. That text does support what you expect. It clearly says that comments are part of the next procedure, not the preceeding one.
StuartR


LisaGreen
5StarLounger
Posts: 964
Joined: 08 Nov 2012, 17:54

Re: VB> Strangeness

Post by LisaGreen »

!t's happened again!!!

Lisa
prob 1b.PNG
You do not have the required permissions to view the files attached to this post.

User avatar
Doc.AElstein
BronzeLounger
Posts: 1499
Joined: 28 Feb 2015, 13:11
Location: Hof, Bayern, Germany

Re: VB> Strangeness

Post by Doc.AElstein »

Something to do with the line continuation in conjunction with blanks again I expect ..
NoLineContinuation.JPG : https://imgur.com/QTYLAh8" onclick="window.open(this.href);return false;
LineContinuation.JPG : https://imgur.com/VTq0aG7" onclick="window.open(this.href);return false;
LineContinuation .JPG : https://imgur.com/7ZdJuSF" onclick="window.open(this.href);return false;


Edit P.S. This is not particularly a characteristic of Sub or Function statements, as far as I can tell . It is something to do with those line continuation things _
PS_ThisIsNothingSpecificallyToDoWithSubStatements.JPG : https://imgur.com/oB9NnAX" onclick="window.open(this.href);return false;
PS_ThisIsNothingSpecificallyToDoWithSubStatements .JPG : https://imgur.com/DAp9LWk" onclick="window.open(this.href);return false;
PS_ThisIsNothingSpecificallyToDoWithSubStatements .JPG : https://imgur.com/A4mreYl" onclick="window.open(this.href);return false;
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also

LisaGreen
5StarLounger
Posts: 964
Joined: 08 Nov 2012, 17:54

Re: VB> Strangeness

Post by LisaGreen »

HEllo everyone,

Does this look okay??

Many TIAs
Lisa
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78485
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VB> Strangeness

Post by HansV »

Yep, it does.
Best wishes,
Hans