VB.NET IDE Bug - IF..THEN

D

Don

I have discovered a bug in the Current Statement highlighting in the VB.NET
IDE that occurs under a specific set of circumstances. This is the specific
set of circumstances :

- You have a Try..Catch..Finally or Try..Finally block in your code
- The Finally section has one or more single-line IF..THEN or IF..THEN..ELSE
statements

The problem occurs with the last IF..THEN (or IF..THEN..ELSE) line in the
Finally section as follows:

1. With an IF..THEN statement, if the condition is False, the Current
Statement will continue on to the True branch and appear as though it is
executing it, but it is not.

2. With an IF..THEN..ELSE statement, if the condition is True, the Current
Statement will go the the True branch, then continue on to the False branch
and appear as though it is executing it as well. In reality, only the code
for the True branch is executed.

Here is some example code that will illustrate the problem. Put a breakpoint
on the first line of code and watch the magic:


Example 1.

Try

Finally

If False Then Console.WriteLine("1true") ' Works fine
If False Then Console.WriteLine("2true") ' Works fine
If False Then Console.WriteLine("3true") ' Works fine
If False Then Console.WriteLine("4true") ' Whoops...

End Try


Example 2.

Try

Finally

If True Then Console.WriteLine("1true") Else Console.WriteLine("1false")
' Works fine
If True Then Console.WriteLine("2true") Else Console.WriteLine("2false")
' Works fine
If True Then Console.WriteLine("3true") Else Console.WriteLine("3false")
' Works fine
If True Then Console.WriteLine("4true") Else Console.WriteLine("4false")
' Whoops...

End Try


As far as I can tell, the bug is simply cosmetic: even though it shows it's
executing the wrong branch, it really isn't.

- Don
 
D

Don

This bug also occurs in the Catch section, but not in the Try section, of a
Try..Catch and Try..Catch..Finally block.

- Don
 
H

Herfried K. Wagner [MVP]

* "Don said:
I have discovered a bug in the Current Statement highlighting in the VB.NET
IDE that occurs under a specific set of circumstances. This is the specific
set of circumstances :
If False Then Console.WriteLine("1true") ' Works fine

I remember there was a bug with single line 'If...Then' statements which
occured under various circumstances... I don't find the discussion about
this issue at the moment.
 
C

Chris Dunaway

I remember there was a bug with single line 'If...Then' statements which
occured under various circumstances... I don't find the discussion about
this issue at the moment.

That is a known bug, but I thought it was fixed in VS.Net 2003. Is that
not the case?
 

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