+3  A: 

This is part of the editor you are using, they may behave differently but the fact is VB really is case-insensitive language. So, ss and SS are same.

Please have a look at VB.Net Basics tutorial for more info :)

Sarfraz
oh, that's interesting. is there some place i look this detail up? i haven't yet tested, but thinking about VBScript, you may be right.
Otaku
@Otaku: please see my answer again i have provided the link now. Thanks
Sarfraz
I'm quite familiar with VB, thank you :) I'm not sure what you want me to look at on that page.
Otaku
@Otaku: ok then that is good to listen to :) Thanks
Sarfraz
+3  A: 

I'm not sure I understand you? VB is case insensitive, so ss and SS is the same variable, so the compiler correctly complains that you re-declared the variable.

I think that Variables are not case sensitive, but function names are.

Michael Stum
but if I use `ss` and then later type `SS`, it gets autocorrected to `ss`, which leads to me believe that the compiler does indeed care about case.
Otaku
@oTAKU: That's the IDE changing the case, not the compiler.
John Saunders
VB still doesn't really care about case. The IDE is trying to clean the code to have variables remain the same throughout.
guitarthrower
+1  A: 

Yes, VB is case insensitive. It sometimes throws those not used to it for a bit of a loop.

Xorlev
+7  A: 

VB is mostly case insensitive, but there are exceptions. For example, XML literals and comprehension is case sensitive. String comparisons are usually case sensitive, unlike say T-SQL, but there are compiler switch to make string comparisons case insensitive. And of course there are the edge cases when dealing with inheritance, COM, and Dynamic Language Runtime.

Jonathan Allen
Good points on where case does matter like XML Literals and string comparisons. But when we say it is **mostly** case insensitive, what exactly are we talking about? Moving over to Outlook VBA, just as an example, if I type `Dim mi as mailitem` and `subject = mi.subject`, the object names will get auto-corrected to `MailItem` and `mi.Subject`. Does the compilier care (because it will *always* auto-correct this) or is this pretty code or...?
Otaku
The compiler doesn't care. You could test this by editing a file in notepad and using the command-line compiler.
Jonathan Allen
Yeah, just tried this. That proves it. Thanks Jonathan.
Otaku
+20  A: 

The difference between VBA and VB.Net is just because VB.Net compiles continuously in the background. You'll get an error when you compile the VBA.

Like Jonathan says, when programming you can think of VB.Net as case-insensitive apart from string-comparisons, XML, and a few other situations...

I think you're interested in what's under the hood. Well, the .NET Common Language Runtime is case-sensitive, and VB.Net code relies on the runtime, so you can see it must be case-sensitive at runtime, e.g. when it's looking up variables and methods.

The VB.Net compiler and editor let you ignore that - because they correct the case in your code.

If you play around with dynamic features or late-binding (Option Strict Off) you can prove that the underlying run-time is case-sensitive. Another way to see that is to realise that case-sensitive languages like C# use the same runtime, so the runtime obviously supports case-sensitivity.

EDIT If you want to take the IDE out of the equation, you can always compile from the command-line. Edit your code in Notepad so it has ss and SS and see what the compiler does.

EDIT Quote from Jeffrey Richter in the .NET Framework Design Guidelines page 45.

To be clear, the CLR is actually case-sensitive. Some programming languages, like Visual Basic, are case insensitive. When the VB compiler is trying to resolve a method call to a type defined in a case-sensitive language like C#, the compiler (not the CLR) figures out the actual case of the method's name and embeds it in metadata. The CLR knows nothing about this. Now if you are using reflection to bind to a method, the reflection APIs do offer the ability to do case-insensitive lookups. This is the extent to which the CLR offers case-insensitivity.

MarkJ
Best answer I've heard so far. Is there someway to prove this point that *VB.Net compiler and editor let you ignore that*? Is there a way to some how turn off the auto-correct? Or is there a way to compile an sln that is *not* written in VS IDE in MSBuild that uses both `ss` and `SS` and it will compile and work as expected?
Otaku
You can turn off auto-correct by cheating. Right-click on a vb file and select "Open With". Then pick something like "XML (Text) Editor". You will lose all the VB-specific functionality like auto-correct.
Jonathan Allen
Good additions, thank you!
Otaku
+3  A: 

Yes, the VB.NET compiler treats identifiers in a case insensitive way. And yes, that can cause problems when it consumes assemblies that were written in another language or uses COM components. The former case is covered by the Common Language Specification. The relevant rule is:

For two identifiers to be considered distinct, they must differ by more than just their case.

Hans Passant
+7  A: 

Part of the problem here is you need to divide the language form the IDE experience.

As a language VB.Net is certainly a case insensitive with respect to identifiers. Calling DateTime.Parse and datetime.parse will bind to the exact same code. And unlike languages like C# it is not possible to define methods or types which differ only by case.

As an IDE VB.Net attempts to preserve the case of existing identifiers when it pretty lists a block of code. Pretty lists occur whenever you move off of the current logical line of code. In this case you move off of the second declaration of SS, the pretty lister notices there is an existing identifier with that name and corrects it to have matching case.

This behavior is though is purely done as a user value add. It is not a part of the core language.

JaredPar
Thanks Jared, interesting to know that it is only the IDE. I still fail to understand why it would be a good thing to have more than one name represent different things by just case difference in the name, but I guess that's for another day.
Otaku
I don't think Jared meant it's **only** the IDE. I think he has said the compiler is case-insensitive, so it thinks `ss` is identical to `SS`, but also as an aid to reading the IDE corrects `SS` to `ss` as you type. So even if the IDE didn't correct the case, the compiler would still see the two identifiers as identical.
MarkJ
A: 

One doesn't have to try all that hard in vb.net to create code with different uppercase/lowercase "spellings" of an identifier. Changing the casing of an identifier in the file where it's declared without using the "Rename" function will not cause the name to be updated in other files, though editing any line which contains the name will cause it to conform to the present definition.

In this way, one can determine that vb.net is mostly case insensitive, but it does make the case of identifiers available to the CLR which may use that information in case-sensitive ways.

supercat