If you press Break at this point you are already beginning the debugging process!

[Spoiler: The solution is For x As Integer = 0 To 4 because array-indexing starts at zero.]

When debugging you can step-through your code one line at a time, observe what happens to your variables, jump to specific lines, etc., etc. To START THE PROCESS you can:

1. Choose the Debug menu and Step Into (or press the F11 or F8 function key).

Continue to press F11, stepping through your code one line at a time.

WHAT YOU CAN DO WHILE STEPPING THROUGH

Point your mouse over any variable (and other values) and a pop-up will display its current value. If it is, for example, an array then you can click on the plus sign that appears within the pop-up to expand it, showing more details that you can navigate through.

This works for object-references, etc., as well, and you can navigate through entire structures!

As you are stepping through there are two other options on the Debug menu: Step Over (F10 or Shift-F8) and Step Out (Shift-F11 or Ctrl-Shift-F8).

Step Over: If you are about to call another function or method, just run through it without pausing, returning to the current code block.

Step Out: If your code has called (moved into) another function or method then complete this without pause, returning to the previous (calling) code-block.

You can also drag the yellow arrow on the left up or down to skip, or re-execute, lines;
You can right-click a line and choose Run to Cursor (Ctrl-F10).

You can abandon debugging at any point by pressing the red square (Stop Debugging) (Shift-F5 or Ctrl-Alt-Break). Or press the Start button, which now says Continue (F5) to run the rest of your code. (Generally it is better to let the code run to completion, particularly for more complex applications, so that all object-references are correctly disposed of.)

***************

2. Click to the far left of a statement to create a Breakpoint (F9) - repeat to remove the breakpoint (this is available from the Debug menu as well). Press Start and the code will run until it reaches the breakpoint and then pause for you to step through.

You can set a number of Breakpoints - Ctrl-Shift-F9 removes all breakpoints.

Refer back to point 1. for details of what you can do while stepping through.

3. Right-click an executable line (not a comment) and choose Run to Cursor (Ctrl-F10) - my favourite method! The code will run all the way until it reaches this line (assuming, of course, that your code will actually encounter this line).

Refer back to point 1. for details of what you can do while stepping through.

4. In VB you can type the word Stop on a line and then press Start; it will run to this line and then pause/stop and you can continue stepping-through. This is useful if you know that you will probably need to test the same section of code many times, and over several sessions. (Don't forget to delete the word Stop when you've finished!) Generally, though, you might prefer to use a Breakpoint rather than Stop.

Refer back to point 1. for details of what you can do while stepping through.

Locals Window
The Locals Windows will display the values of all (currently in scope) variables, including arrays, lists, etc. Once you have started debugging choose the Debug menu, Windows, Locals (Alt-4).

Note The Debug, Windows menu option only shows a limited number of windows until you actually start debugging - then many other windows become available to you. Investigate the Immediate, Watch and Call Stack Windows.

The Locals window appears as a separate tabbed panel (usually to the bottom-left of the screen) alongside the Output and other windows.

MSDN: I've linked to the VS 2010 version, rather than 2012, to avoid the distraction of any Metro features.

Thank you very much. I quite agree, the more people I can persuade to read this the better

I have given this link to a few people. I just hope that they actually read it and tried it. I am no expert but, not a beginner and i have to debug some of my code sometimes. I think it should be one of the first things they teach in computer programming classes. I also think they should teach them to use the Option Strict and Option Explicit options in there code. That helps prevent some errors before they happen.

Hello @x-logan. I've attempted to describe their use in the Module below.

If, while stepping-through, your code calls another procedure or function, then Step Out will complete this procedure (without pause), returning to the next line of the original (calling) procedure.

If, while stepping-through, your code is about to call another procedure or function, then Step Over will run that procedure in its entirety (without pause) returning to the next line of the current code.

As you can tell from the descriptions, they are very similar options. The only difference is whether the other/secondary procedure has already been called (entered).

Module Module1
'Add a breakpoint to the following procedure (F9)
'perhaps calling it from the Click event of a button.
Sub StepThroughThis()
'Use F11 - Step Into
StepOut() 'will then call the next procedure..
'choose Step Over (F10) will run StepOver in its entirety,
StepOver()
'returning to this procedure
End Sub
Sub StepOut()
'.. you'll arrive here
'choosing Step Out now (Shift-F11) will complete
'this procedure without pause, returning to
'the StepThroughThis() procedure
MessageBox.Show("This message will be displayed")
End Sub
Sub StepOver()
MessageBox.Show("This other message displayed")
End Sub
End Module