If-Then-Else - both parts execute!

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
 
A

Armin Zingler

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
 
D

Dennis

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?
 
C

Cor Ligthert[MVP]

Bill,

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

Cor
 
B

BillE

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?
 
J

joecool1969

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?
 
B

BillE

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?
 
G

Göran Andersson

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.
 
G

Göran Andersson

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. :)
 

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