1

While debugging a VB6 program it would be useful to output a fairly large multidimensional array in the immediate window. That would enable copy/paste to another editor for analysis and would be easier than clicking through the array in the locals window.

However I'm unsure of how to use looping syntax in the immediate window - or even if this is possible.

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81

2 Answers2

5

You can use the colon (:) to separate statements on a single line. For instance:

for x=0 to 2:for y=0 to 2: ? myData(x,y): next : next

Result:

This is 0 0
This is 0 1
This is 0 2
This is 1 0
This is 1 1
This is 1 2
This is 2 0
This is 2 1
This is 2 2

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
3

After more messing around than this should have required, it turns out the answer is:

Although most statements are supported in the Immediate window, a control structure is valid only if it can be completely expressed on one line of code; use colons to separate the statements that make up the control structure. The following For loop is valid in the Immediate window:

For I = 1 To 20 : Print 2 * I : Next I

(which is formally documented here.)

Some additional details:

  • Variables in the immediate window do not require declaration -- even if Option Explicit is used in the module / program being run. This makes arbitrary for-looping convenient (but also makes mistakes easier when trying to reference variables in current scope).

  • Printing can be done with any of: Debug.Print, just Print or ?

  • Nested loops work.

Community
  • 1
  • 1
StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
  • In hindsight this seems kind of obvious. Unfortunately some unrelated syntax error (resulting from the un-readability of the long single-line in the immediate window I was using!) obfuscated that this actually does work, when I first tried it. – StayOnTarget Jul 19 '16 at 14:25