Blasted parentheses!

  • Thread starter Thread starter Norm Dotti
  • Start date Start date
N

Norm Dotti

In VS 2002 I could specify

Dim x As System.Windows.Forms.Form()

or

Dim x As System.Windows.Forms.Form

and everything was ok. Since upgrading to VS 2003 it won't
let me put in the parentheses in the above sample. After I
installed VS 2003 and opened up my 2002 project I answered
yes to the question about updating the project. Why didn't
it take my parens out?

Now I have a situation where some of my code has parens
and some don't. It seems that if I press Enter from a Try
statement, it goes through the code in that block and
takes them out for me but doesn't do anything anywhere
else.

Allowing this mixed mode type specification has led to
exceptions such as "Only one WebServiceBinding attribute
may be specified on type MyWebService" and other things.
It seems that I have to go through all my code to make
sure the parens are gone?

The VS 2003 docs show the parens as valid (see ms-
help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vbcn7/html/vaco
nWritingdeclarations.htm) yet the IDE doesn't allow them
and they didn't get converted at all. Am I missing
something or is there some easy way to fix this?
 
Dim x As Type() declares an array. Dim x as Type declares it as an
object of that type. I don't know why it won't allow that, but I'd
suggest to declare array variables as Dim x() As Type to avoid
possible confusion (especially with the New keyword).

-mike
MVP
 
Norm,
Are you missing something in your example?
Dim x As System.Windows.Forms.Form()
is an array of forms
Dim x As System.Windows.Forms.Form
is a single form.

Which in VS.NET 2002 are entirely different constructs.

In VS.NET 2002 there was a 'problem' when you had Operator New to create a
single Form:
Dim x As New System.Windows.Forms.Form()

And you deleted the Operator New keyword
Dim x As System.Windows.Forms.Form()

You were left with an array of forms.

Which causes all sorts of compile & runtime errors. Which sounds
suspiciously like your problem.

VS.NET 2003 changed it to remove the () on the constructor
Dim x As New System.Windows.Forms.Form

So when you delete the New keyword
Dim x As System.Windows.Forms.Form

You are still left with a single item.

I've only seen the parentheses disappear during upgrading when the Operator
New was involved.

I would recommend putting Option Strict On at the top of each source file,
you will receive compile errors instead of hard to track down runtime
errors. Of course you will receive additional errors where you are relying
on late binding.

Hope this helps
Jay
 
My bad. I meant to have the New keyword in there. I'm not
trying to do anything with an array nor have I removed a
New from the Dim statement.

So in 2002 it forced me to have:

Dim x As New System.Windows.Forms.Form()

In 2003 it forces me to have:

Dim x As New System.Windows.Forms.Form

Why didn't the upgrade wizard catch that? Is there some
way to have VS correct this for me rather than modifying
every Try block (essentially pressing Enter and then
Backspace to get it to go through and verify the code)?

Setting Option Strict On in the source file doesn't catch
this problem. I set Option Strict On in the project file
but I can't do that because I need to do late binding for
some things.

Any other ideas?
 
I didn't have any problems initially. It's run fine for
about a week now. It wasn't till I started changing code
(nothing that would have generated the exception I was
getting) that I started getting flakiness. One exception I
got was "only one WebServiceBinding attribute may be
specified on type MyWebService". Once I took the parens
off this particular Dim x as New webservice... it worked.

I don't really want to convert back. The update doesn't
take out the parens. I tried a simple app to verify. I
will contend that the upgrade should have removed them as
the IDE doesn't allow it (I understand you have to do
a "refresh" to get rid of them). So why the ambiguity?
Now, depending on what code you touch, some of your
statements have parens and some don't. Don't know that
this was causing the problems.

Do you know of any way to "refresh" an entire file?

Thanks.

-----Original Message-----
Norm,
No!

VS.NET 2003 fully support both:

Dim x As New System.Windows.Forms.Form()
Dim x As New System.Windows.Forms.Form

Well the compiler does anyway. The IDE will insist on removing the () on the
first line, if you use Edit Undo right away it will come back, then using
the mouse click someplace else it will stay, Run the program that line will
work as you expect. The () will stay until
VS.NET 'refreshes' that block of
 
Norm,
I'm running .NET 1.1, whether I include the () or not on the construction of
the object (operator new), I do not receive runtime errors!

If you want to really find the problem use Option Strict On! Which means you
need to stop relying on Late Binding. Normally I isolate my Late Binding
into one small corner of my application that I do not include Option Strict
On, for when I really need Late Binding.

If you get a reproducible sample, I can try it, just to make sure its not
something odd with your machine. Or that it is something that we need to
report as a bug.

Hope this helps
Jay
 
Sigh...as it turns out, this was far less reproducable
than I was originally led to believe. In reality, it
happened twice and is not in fact reproducable at this
point.

We are using VSS and I was able to revert back to the
version of the code that exhibited the problem, but today
the binary gods were working in my favor and it didn't
cause a problem. I tried it from three different machines,
including the one that got the runtime exception
yesterday. We will continue to monitor this behavior to
see if it happens again. For now, I'll consider it a fluke
and move on.

We have not upgraded VSS to 6.0d from 6.0c. Are there any
compelling reasons to do so?

Thanks for your help Jay.
 
Back
Top