Option Strict Off/On

G

Greg

We have an application in our office that has the Option Strict option set to
off right now. I do understand it should be set to ON, but right now, I'm
just going to continue with it this way since I do not have the time to fix
everything to set it to ON.

Anyway, my question is if its set to OFF why is it it keeps getting set back
to ON, everytime we move the package from one machine to another. It's the
Option Strict option specific to the project?

So, how can I get the Option Strict option for this project to stay at OFF?

Thanks.
 
A

Andrew Morton

Greg said:
So, how can I get the Option Strict option for this project to stay
at OFF?

Just type Option Strict Off as the first line of every code file.

That way, it keeps silently nagging you to do something about the faulty
code. :)

Andrew
 
P

Phill W.

Greg said:
We have an application in our office that has the Option Strict option set to
off right now. .. . .
why is it it keeps getting set back to ON, everytime we move the package
from one machine to another. It's the Option Strict option specific to the
project?

There's another one!
There's a "default" for /all/ projects that's set at the IDE level. If
these are the way they're /supposed/ to be (i.e. On), you'll have to
switch it off again, every time.

Quick fix:
Stick the line

Option Strict Off

at the top of each source file. (It also acts as a visual reminder that
you've done this).

HTH,
Phill W.
 
P

Patrice

Which kind of application ? It could be also part of the web.config file if
ASP.NET...

As others suggested my personal preference would be also to let this anyway
be On by default and to set this Off in each source file that really needs
this...

This way you are taking good habits for new code and you can fix the old
code on a file by file basis...
 
G

Greg

OK, I've got it with regards to setting Option Strict in code for each file.
In fact, I just took the time today to make sure all the code is correct to
all Option Strict ON, which is best anyways.

But, what my question was though, if I set the Option Strict to OFF in the
Project's My Project tab/screen for a specific project, why would it keep
getting set back to ON, when it was changed for the project to be OFF? I
thought these were project specific settings.

I'm concerned that Visual Studio is changing settings I have already made
without notifying me. If I set Option Strict to OFF in my project, it seems
it should stay that way unless I change it. Or, is the Option Strict / Option
Compare and Option Explicit always changed back to default values regardless
of what I set them to?

This is what my question is, "Why does the Option Strict keep getting set to
ON, when I have specifically set it to OFF for my project?". I'm not having
problems with it now since I have fixed my code, I just want to know why it
keeps getting set back to ON everytime.

Thanks,
Greg
 
C

Cor Ligthert[MVP]

Greg,

Your options are not project settings, it are your personal settings for
Visual Studio.

Cor
 
L

Linda Liu[MSFT]

Hi Greg,

There're two levels of settings for VB projects.

On setting is set on an Visual Studio IDE instance.

Click the Tools -> Options menu item, and select the "Projects and
Solutions | VB Defaults" node in the Option dialog. The default VB project
setting values are shown on the right hand. A new VB project will take
these default values when being created. But changing the values of the
default setting won't affect the existing VB projects.

The other setting is set on an individual VB project.

Right click on a VB project in the Solution Explorer and choose Properties.
In the Project Designer, switch to the Compile tab. The Option explicit,
Option strict and Option compare settings are shown on the right hand.
These settings are set on this particular project.

No matter what values of the VB default setting you set on the VS IDE, if
the 'Option explicit' value of this project is other than 'On' or the
'Option strict' value is other than 'Off' or the 'Option compare' value is
other than 'Binary', the value is stored in the project file(.vbproj)
respectively.

Open the .vbproj file with Notepad, you can find these values in first
<PropertyGroup> tag if any. For example:

<?xml version = "1.0" encoding="utf-8">
<Project DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
...
<OptionStrict>On</OptionStrict>
</PropertyGroup>
...
</Project>

If you change the 'Option Strict' value to 'Off' after you set it to 'On',
the value stored in the .vbproj file will become 'Off'.

As for your problem, it seems that the .vbproj file is changed when you
move the package from a machine A to a machine B. You may open the .vbproj
file with Notepad to check the 'OptionStrict' value on the machine B.

If you couldn't find the 'OptionStrict' tag, the value of this setting in
the Project Designer should be displayed as 'Off'; otherwise, the value
displayed in the Project Designer depends on the value stored in the
project file.

Hope this helps.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Michael D. Ober

Linda Liu said:
Hi Greg,

There're two levels of settings for VB projects.

On setting is set on an Visual Studio IDE instance.

Click the Tools -> Options menu item, and select the "Projects and
Solutions | VB Defaults" node in the Option dialog. The default VB project
setting values are shown on the right hand. A new VB project will take
these default values when being created. But changing the values of the
default setting won't affect the existing VB projects.

The other setting is set on an individual VB project.

Right click on a VB project in the Solution Explorer and choose
Properties.
In the Project Designer, switch to the Compile tab. The Option explicit,
Option strict and Option compare settings are shown on the right hand.
These settings are set on this particular project.

No matter what values of the VB default setting you set on the VS IDE, if
the 'Option explicit' value of this project is other than 'On' or the
'Option strict' value is other than 'Off' or the 'Option compare' value is
other than 'Binary', the value is stored in the project file(.vbproj)
respectively.

Open the .vbproj file with Notepad, you can find these values in first
<PropertyGroup> tag if any. For example:

<?xml version = "1.0" encoding="utf-8">
<Project DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
...
<OptionStrict>On</OptionStrict>
</PropertyGroup>
...
</Project>

If you change the 'Option Strict' value to 'Off' after you set it to 'On',
the value stored in the .vbproj file will become 'Off'.

As for your problem, it seems that the .vbproj file is changed when you
move the package from a machine A to a machine B. You may open the .vbproj
file with Notepad to check the 'OptionStrict' value on the machine B.

If you couldn't find the 'OptionStrict' tag, the value of this setting in
the Project Designer should be displayed as 'Off'; otherwise, the value
displayed in the Project Designer depends on the value stored in the
project file.

Hope this helps.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Huh? The simplest solution is to put the three option statements at the top
of each file. This way the option settings are in the file. Linda, can a
change be made to the next version of the VB IDE to copy the option settings
from the project (or IDE) to the top of the file as soon as the file is
created (similar to the VB6 IDE)?

Mike Ober.
 
P

Patrice

Actually you should be already able to dot that by updating your VS.NET
templates i.e. when you create a file it actually copies a template. Upading
this template should do the job...

This is not exactly the same as you wouldn't be able anymore to change this
globally on the fly. IMO the best option would be to find out if VS really
sometimes change this by itself and if yes, to fix this behavior...
 
C

Cor Ligthert[MVP]

Michael,

You can better ask this to an MVP like Herfried, Bill or Seth (now) they
have contact with the product team, normally Linda does not.

:)

(Yes I too and I have placed your question there)

:)

Cor
 
G

Greg

Thanks for the followup. I looked at the .vbproj file in Notepad and I see
that it is set correctly as <OptionStrict>Off</OptionStrict>. With this in
mind, it really concerns me that when I move the application from one machine
to another that this would get changed or lost. So, with this happening, what
else could possibley happening that I'm not noticing?

Anyway, the good thing about this happening to me is I have updated about
150+ lines of code that would have caused problems with the setting to OFF.
So, it forced me to write clearner code overall, which is what I wanted
anyways.

But, aside from this, I think it might be a good idea for Microsoft to look
into this. I'm not so much concerned about the Option Strict setting so much,
but I think who ever was responsible for this portion of VS.Net, should have
his/her code/work double checked to make sure no other much more critical
settings are not being lost or changed without the developers knowledge.

I do however, still absolutely love Visual Studio.Net / Visual Basic.Net,
and who knows maybe soon I will add C#.Net to that as well. I solute
Microsoft for providing such awesome development tools.

Thanks,
Greg

Thank again.
 
C

Cor Ligthert[MVP]

Greg,

It takes some time and sometimes double casting, however I never had any
need to keep option strict off. (Maybe I come to it once, however sometimes
will casting over casting help a lot

a = DirectCast(A, DirectCast(b,c).d

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top