0

I was fooling around with the Option settings in Visual Studio 2015 and I noticed an odd thing, after setting Option explicit to Off in three places I still get a error message saying "Declaration expected" if I try to use a variable without declaring it first. I set it to off in the properties of the project, by going to Tools>options>Projects and Solutions> VB Defaults, and in the code. Below is the code from a simple class I created just to test this.

Option Explicit Off
Public Class Class1
    Test = "1"
End Class

The read squiggle appears under the undeclared Test variable. I have no intentions of turning Options explicit off in a real project but I wonder what the point is of having the option to do so if invoking it doesn't do anything. I'd appreciate a response from anyone who could enlighten me.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
  • This is a simple syntax error, do you have a reproducible example? – asawyer Oct 27 '16 at 13:43
  • 4
    Try putting `Test = "1"` inside a method. I think even with `Option Explicit` off, you still have to give class members types. Also, you may still need to use `Dim`. – Chris Dunaway Oct 27 '16 at 13:43
  • Have a look at [this](http://stackoverflow.com/questions/2454552/what-do-option-strict-and-option-explicit-do). The answer marked **TL;DR** is pretty good which gives you an example. – Bugs Oct 27 '16 at 13:48
  • Hello Chris, of course you are right the assignment had to be inside of a method. Once I did that the error was resolved and no Dim was required. Thanks for your response. – user1788680 Oct 27 '16 at 14:13

0 Answers0