I have an if sentence in my vb.net windows form

'If StrComp(WindowState.ToString, FormWindowState.Minimized.ToString) = 0 Then
If Me.WindowState <> System.Windows.Forms.FormWindowState.Normal Then
'[Object].ReferenceEquals(WindowState, FormWindowState.Minimized) Then 
' System.Windows.Forms.FormWindowState.Minimized Then  ' FormWindowState.Minimized Then
...

The evaluation, as you can se I have tried in different ways, evaluates to true even it should be false. The value is normal and it shows me while debugging or printed out in a msgbox. What I want it to do is having it to go into the if-condition when the value is minimized. My simplest surgestion was "IF (me.WindowState = System.Windows.Forms.FormWindowState.Minimized ) Then" but this does not work. What am I missing???

Dani AI

Generated

This thread shows classic debugger/source mismatch rather than a logic bug. observed the debugger "stepping into" the If even when the body never ran; 's suggestion about If mBool = True is functionally identical to If mBool Then and would not change that behavior. When the IDE is showing a different IL map than the source file, the debugger can highlight the condition line while the runtime is executing different code (or an optimized/released build).

Recommended quick checklist:

  • Clean the solution, delete bin/obj and do a full Rebuild.
  • Confirm the project is built in Debug configuration and that code optimization is off.
  • In the debugger open Debug -> Windows -> Modules and verify the loaded assembly path and that its symbols (PDB) are loaded for the project being stepped into. Load symbols manually if needed.
  • Use the Watch/Immediate window (for example: ? mBool or evaluate the numeric value of the enum) to inspect the exact runtime value instead of only relying on editor highlighting.
  • Check for duplicate assemblies (old DLL in bin, GAC, or a different output folder) and for multiple instances/threads that might be changing the value between evaluation and stepping.
  • If stepping confusion persists, restart Visual Studio and the app to clear cached symbols and try again.

A short runtime diagnostic log can help confirm what the runtime actually sees:

System.Diagnostics.Debug.WriteLine("WindowState: " & Me.WindowState.ToString() & " (num=" & CInt(Me.WindowState) & ")")

Notes: multi-threading, conditional compilation, or "Edit and Continue"/optimization can make stepping misleading. The safest route is to confirm values from the Immediate/Watch windows and verify symbols/modules match the source; once symbols and build configuration match, the If/Then stepping will reflect real execution.

Recommended Answers

All 3 Replies

Very interesting.. No matter what I feed to the if it gets into the then If I say:
dim mBool as boolean = true
if mBool Then
..

it gets into it. If I say

dim mBool as boolean = false
if mBool Then
..

it gets into it..

WTF....!?!?

Member Avatar for Member #46692

Shouldn't you be saying something like: if mBool = true Then as opposed to: if mBool Then

Shouldn't you be saying something like: if mBool = true Then as opposed to: if mBool Then

Same same..

But I found the problem/issue. The compiler debugs into the Then but does not do the actions. Two same if sentences and it will enter the last one (but not do anything in it, just steps through). A compiler-error of some kind while debugging..

Well, problem/issue solved.. Thanks for reading along.. :)

Have a lovely evening:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.