If-Then-Else - both parts execute!

  • Thread starter Thread starter BillE
  • Start date Start date
B

BillE

VS2008 VB.NET
While debugging code recently I found that in some cases both parts of an
If-Then-Else statement were executing.

For example:

dim bl as boolean = false
dim i as integer
if bl then
i=1
else
i=2
end if

While stepping through the code, first the i=1 would execute then the i=2
would execute. I resorted to
if bl then
i=1
end if
if not bl then
i=2
end if

I wonder how this could happen?
Thanks
Bill
 
BillE said:
VS2008 VB.NET
While debugging code recently I found that in some cases both parts
of an If-Then-Else statement were executing.

For example:

dim bl as boolean = false
dim i as integer
if bl then
i=1
else
i=2
end if

While stepping through the code, first the i=1 would execute then the
i=2 would execute. I resorted to
if bl then
i=1
end if
if not bl then
i=2
end if

I wonder how this could happen?

I wonder, too. Can't repro the problem. Have you tried the first
example exactly as posted here? Obviously it's not been copied from the
source code window.


Armin
 
VS2008 VB.NET
While debugging code recently I found that in some cases both parts of an
If-Then-Else statement were executing.

For example:

dim bl as boolean = false
dim i as integer
if bl then
i=1
else
i=2
end if

While stepping through the code, first the i=1 would execute then the i=2
would execute.

Are you setting breakpoints in this code? Where?
 
Bill,

You did not apparently getting the message build errors continue Yes or No
and you decided to take yes?

Cor
 
Optimizations are enabled - I need to understand this better, obviously. I
should uncheck this when in Debug mode?

In VS2005, on the Compile tab, there was a dropdown to switch between Debug
and Release, but in VS2008 this dropdown is gone. How do I switch between
Release and Debug mode in VS2008?
 
Optimizations are enabled - I need to understand this better, obviously. I
should uncheck this when in Debug mode?

In VS2005, on the Compile tab, there was a dropdown to switch between Debug
and Release, but in VS2008 this dropdown is gone.  How do I switch between
Release and Debug mode in VS2008?

"Patrice" <http://www.chez.com/scribe/> wrote in message

In my copy of VS2008, the Solutions Configurations dropdown with
Debug, Release and Configuraton Manager (new with 2008 I think) is
right there where it always has been.

Maybe you have the "Standard" menu disabled?
 
I was looking on the project properties page. I found it on the Solutions
properties as you said, thanks.
Bill
Optimizations are enabled - I need to understand this better, obviously. I
should uncheck this when in Debug mode?

In VS2005, on the Compile tab, there was a dropdown to switch between
Debug
and Release, but in VS2008 this dropdown is gone. How do I switch between
Release and Debug mode in VS2008?

"Patrice" <http://www.chez.com/scribe/> wrote in message

In my copy of VS2008, the Solutions Configurations dropdown with
Debug, Release and Configuraton Manager (new with 2008 I think) is
right there where it always has been.

Maybe you have the "Standard" menu disabled?
 
BillE said:
VS2008 VB.NET
While debugging code recently I found that in some cases both parts of an
If-Then-Else statement were executing.

For example:

dim bl as boolean = false
dim i as integer
if bl then
i=1
else
i=2
end if

While stepping through the code, first the i=1 would execute then the i=2
would execute. I resorted to
if bl then
i=1
end if
if not bl then
i=2
end if

I wonder how this could happen?
Thanks
Bill

It can't happen.

If you have set breakpoints in both cases, then the probable reason is
that the code is executed twice with different values for bl.
 
Michael said:
I have had this happen in both C# and VB (VS 2008 Standard). The
solution is to delete the bin folder under your project and recompile.

Mike Ober.

Ok, but then it was because the debug information was out of phase with
the code. So it actually didn't happen, it only looked like it did. :)
 
Back
Top