4

Something we can just put break point on while making sure it doesn't do anything else.

In c, that would be while(false);

What to do in vb.net?

user4951
  • 32,206
  • 53
  • 172
  • 282

8 Answers8

10

If you always need it to break there you can put Stop or Debugger.Break()

pinkfloydx33
  • 11,863
  • 3
  • 46
  • 63
2

If you really want a No-Op for some reason (could this turn into a contest for the most ineffectual single line of code?!), how about these?

System.Threading.Thread.Sleep(1) - 1ms is unlikely to have a huge impact outside of a loop

Debug.Write("") - doesn't appear to output anything.

AjV Jsy
  • 5,799
  • 4
  • 34
  • 30
2

There is a legitimate use-case for this. When a temporary breakpoint is required after the statement of interest and this is the last line inside an if statement, an extra no-op type statement is required to place the temporary breakpoint on. In this case I use:

If someCondition >0 Then

    doSomething
    Space (1)    'Dummy line to place breakpoint
End If

This returns a string containing one space, but does not assign it to anything. I use it in VBA, but it's also supported in .net

RobD
  • 21
  • 1
2

My two cents...

You can combine any series of commands onto one line with colons:

If False Then : End If
Select Case False : Case Else : End Select

I've also made it into a sub. Then it gets a recognizable name of own:

'Definition...
Public Sub noop () 'Or Private, Protected, etc.
End Sub

'Usage...
Sub Main()
    If sometest Then
        noop
    Else
        MsgBox "test is false"
    End If
End Sub
spinjector
  • 3,121
  • 3
  • 26
  • 56
1

Very strange question, you could place a BreakPoint about anywhere in the code. But here are some useless lines :

 Do While False
 Loop

 While False
 End While

Even the following :

 Dim hello = Nothing

Or this :

 Format("", "")
Abdusalam Ben Haj
  • 5,343
  • 5
  • 31
  • 45
1

A no-op statement is also useful as an aid to document code nicely and make it more easily understandable. You could for example put in a statement like A = A.

For example:

If MyNumber => 100 then A = A
Else:

Michael
  • 11
  • 1
1

I know this is an old query, but for what it is worth, my preferred solution to the original question is Debug.Assert (vbTrue)

If you wanted, you could use a variable instead of vbTrue and then enable/disable all breakpoints in your code by changing one variable

Dim bDisableBreakpoints as Boolean: bDisableBreakpoints = vbTrue
'your code here
Debug.Assert (bDisableBreakpoints)
'rest of your code

Simply change bDisableBreakpoints to vbFalse and the breakpoints will be set wherever you have used Debug.Assert

rolled
  • 11
  • 1
0

My personal favorite is

dim b=1

Then I put a breakpoint there.

user4951
  • 32,206
  • 53
  • 172
  • 282