Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Implicit data type conversion?

Status
Not open for further replies.

IlyaRabyy

Programmer
Nov 9, 2010
571
US
Colleagues,

I'm going through the code written by another programmer some 5-6-7 years ago.
I came across some strange statements that, IMHO, must generate error, but apparently it does not do it coz the code works. In essence, it's a memvar declared as string and later assigned an Int value, e.g.
Code:
Dim BlaBlaBla As String = ""
' And later on
BlaBlaBla = 0
I can't recall that VB6 allowed such implicit data type conversion, but apparently VB .NET 2012 does... or - does it?
Please educate me.
TIA!

Regards,

Ilya
 
Yep, VB6 certainly used to allow it. And yes, VB.NET does it - still does it in VS2019. [tt]Option Strict On[/tt] would catch this for you.
 
Hmm... I look at the Application.Designer, Resources.Designer and Settings.Designer - all three have Option Strict On... and this line of code is in the main cycle, it must have being executed, and it still ain't erring - ?

Regards,

Ilya
 
Just to be certain - Enabling Option Strict does not actually switch this on - it simply inserts Option Strict On in new modules. So, if the module (be it a code, form or class module) does not have the line Option Strict On at the top, then it isn't enforced. And when it IS enforced, it is a design time error, not a run time one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top