|
-
Oct 20th, 2009, 03:00 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Option strict
Hi all,
very short question... I turned option strict on in the properties window of my solution. Do I have to put option strict on above my code aswell?
Thnx
-
Oct 20th, 2009, 03:04 AM
#2
Re: Option strict
No, setting Option Strict On via your solution properties sets it globally. If you need to fine tune it so you have it on and off depending upon the file, then you can add it to the top of your file that you want to be different from the global setting.
For ex:
Turn it on like you did but you have one file where your code needs to have it turned Off. Then you add the declaration to the top of just that file and set it to Off there. It will be off for only that file.
Conversly if you wanted it to be off globally then set it via the solution properties as Off. Then if you want to turn it on in certain files you can declare it at the top of just those files with the On setting.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 20th, 2009, 03:05 AM
#3
Thread Starter
Hyperactive Member
-
Oct 20th, 2009, 04:09 AM
#4
Re: [RESOLVED] Option strict
Also, you might want to make it so that it is turned on by default in any new projects you create. You can do this by going to Tools -> Options -> Expand "Projects and Solutions" -> click "VB Defaults" -> Change Option Strict to ON and then click OK
-
Oct 20th, 2009, 06:40 AM
#5
Re: [RESOLVED] Option strict
Hey,
Can't agree with Chris enough!! This should be on as default, along with Option Explicit and Option Infer.
Gary
-
Oct 20th, 2009, 08:23 AM
#6
Re: [RESOLVED] Option strict
I have my VS Default Options for Explicit = On, Strict = On, Infer = Off, the reason I hae Infer off is because it's really only there for Linq of which none of my clients have the 3.5 framework so I can't use Linq anyways.
-
Oct 20th, 2009, 12:59 PM
#7
Re: [RESOLVED] Option strict
Its not JUST for LINQ though... It also means you dont have to declare the type of a variable if you assign a value to it at the same time as you declare it.
E.g:
vb Code:
Dim X = 10
'X is actually of Integer type
'Not Object type as it would be with Option Infer turned off
I dont understand why you would ever need to turn it off, its not as if it does any harm being turned on. But each to their own
-
Oct 20th, 2009, 03:06 PM
#8
Re: [RESOLVED] Option strict
 Originally Posted by chris128
Its not JUST for LINQ though... It also means you dont have to declare the type of a variable if you assign a value to it at the same time as you declare it.
E.g:
vb Code:
Dim X = 10 'X is actually of Integer type 'Not Object type as it would be with Option Infer turned off
I dont understand why you would ever need to turn it off, its not as if it does any harm being turned on. But each to their own 
Yes, I know that, that's exactly the nature of Infer. However "Dim X = 10" isn't very readable compared to 'Dim X As Integer = 10" the "As Integer" is self documenting.
It's not that having it On does harm, it's that unless you're doing Linq having it Off means you have to explicitly declare the variable types is all.
-
Oct 20th, 2009, 03:17 PM
#9
Re: [RESOLVED] Option strict
Ah, I take your point.
That makes sense, however, out of habit I guess I would never write this:
But having Infer On wouldn't throw a warning.
Gary
-
Oct 20th, 2009, 03:20 PM
#10
Re: [RESOLVED] Option strict
Yeah to be honest I hardly ever use/rely on it because I am used to declaring the types but I do find it useful in some situations.
-
Oct 20th, 2009, 03:39 PM
#11
Re: [RESOLVED] Option strict
 Originally Posted by chris128
Yeah to be honest I hardly ever use/rely on it because I am used to declaring the types but I do find it useful in some situations.
What I think sucks is that Linq requires you to Infer things, to me that logically defeats the purpose of declaring things as a specific type, meaning if you don't know what you're getting back how do you know what to declare it and Linq doesn't let you specify the type you're getting back so the variable's Inferred instead. Kinda backwards like the gay guy in an all male school.
-
Oct 20th, 2009, 03:43 PM
#12
Re: [RESOLVED] Option strict
I totally agree, I've hardly used LINQ but when I did that was exactly what I thought... It seems like a real weird way to work when you consider how the rest of the framework works. I dont understand why they had to make it like that but I'm sure there was a good reason.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|