Question If boolean then is broken

michouis

New member
Joined
Mar 9, 2012
Messages
1
Programming Experience
10+
Hello.

VS2005 - VB Windows App

I have the following sub-routine in my code:

Friend Sub WaitCursor(ByVal wait As Boolean)
If wait Then
Windows.Forms.Cursor.Current = Cursors.WaitCursor
Else
Windows.Forms.Cursor.Current = Cursors.Default
End If
End Sub


Now I notice that if I call WaitCursor(true) and then WaitCursor(true) again, the 2nd time it's called it actually executes both condition branches, sets the cursor to wait and then to default at the same time!!! What in the world is going on here? I have noticed other such misbehaviours when testing a boolean variable, it randonly skips code within the execute block, I mean just jumps to a statement out of sequence!!

Scary. Unless some one can explain this weird behaviour. I mean how can something be both true and false at the same time? This is how it behaves!

Thanks
 
There are only two reasons that I can think of. Either your build is failing and you're still running the old output, in which case what is being executed does not correspond to the code you are seeing, or else something is corrupt, either in your project or on your system. First, try Rebuilding the project. That's Rebuild, not Build. If that fails then the first reason is your issue. If it succeeds then I'd start by creating a brand new project and testing that one function in isolation. If it behaves the same way then there's something wrong with your system. If it doesn't then it may be just your current project that's broken, unless you see similar behaviour in other projects.
 
Have you tried putting a break point at the start of the sub to see how many times it is being fired and what values are being passed in. I have on occassion come across this kind of behaviour in my own code and found out that I was calling it from somewhere else with different data, and this was being fired from an event that I did not expect.

You will be able able to follow the break back to where it was called as VB highlights it.

Regards
 
Back
Top