Variable declaration

Gopher2011

Well-known member
Joined
Mar 3, 2011
Messages
111
Location
South England
Programming Experience
10+
I am looking at some code written by another engineer who has since left the company. He has a module and in that module he has declared Analogues(20). When I scroll down to the function shown below, and right click Analogues - go to definition it takes me to the top of the file, and lands on top of the

"Public Analogues(20) As String"


VB.NET:
Module Module1
    Public Analogues(20) As String

    Public Sub Update()
            TempVal = CDbl(Analogues(1))
    End Sub
End Module


This is the expected, and correct behaviour. However.... When i change the name from :-

"Public Analogues(20) As String"


TO

"Public OldAnalogues(20) As String"

I would have expected it to flag all the 'Analogues' in the file with a red underline to denote no defined declaration.

However this is not the case. When i click on go to definition, it now takes me to another file in the project, and lands on.

VB.NET:
Module Module2
       Public Analogues(7) As String
End Module

This is bad right? This is like, totally random behaviour. How the heck does the program know which one to use at runtime?
 
I should add, option explicit was on, option strict was off.

option explicit should have picked this up right?

I should also turn Option strict on, but it generates 10,000 errors, and the code has gone through quality checks and procedures. I cant change the code without inuring costs to the company.

I just want to know why the variable declaration is broken, expected and normal behaviour or a bug.
 
This is bad right? This is like, totally random behaviour
You should generally use context menu on variable name and choose 'rename' and rename it from that dialog, then all prior references is updated as well. If you don't then variable name is changed but any usage of it breaks.

If the rename cause a name clash between members of two modules you get this problem:
'Something' is ambiguous between declarations in Modules 'Module1' and 'Module2'
To revolve this you have to manually qualify the references to Module1.Something and Module2.Something beforehand ('Find All References', qualify those).

This is one of the down-sides of using Module where type promotion occurs and you can write code void of type qualification.
 
Back
Top