Run in Procedure That Dimensions Array Hangs VB Environment (93674)



The information in this article applies to:

  • Microsoft Visual Basic for MS-DOS
  • Microsoft Basic Professional Development System for MS-DOS 7.0
  • Microsoft Basic Professional Development System for MS-DOS 7.1
  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5

This article was previously published under Q93674

SYMPTOMS

In the interpreter environment, your program may hang causing the computer to quit responding if you have a Run statement in a procedure that also dimensions an array. This problem does not occur in programs compiled with the BC.EXE compiler.

STATUS

Microsoft has confirmed this to be a bug in the products listed above. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

This problem occurs under the following conditions:

  • The Run statement is called with no parameters or with a line number in a procedure.
  • The procedure uses Dim or Redim to dimension an array local to that procedure.
  • The Sub or Function is not a static procedure.
The following example program reproduces the problem:
   ' Warning! This program causes the computer to hang (stop responding).
   Declare Sub sub1 ()
   sub1

   Sub sub1
      Dim y(1)
      y(1) = 1
      Print y(1);
      ' Note: Using Erase on y before Run prevents hanging.
      Run
   End Sub
				
You might use Run with no parameters or Run with a line number to restart a program. This form of Run completely reinitializes the program's environment -- closing files, reinitializing all static data, and de-allocating dynamic arrays.

Several workarounds to this problem are listed below:

  1. Use Erase on the dynamic arrays local to the Sub procedure just prior to using the Run statement. For example, if y() is an array local to the Sub procedure, the following code works around the problem:
          Erase y
          Run
    						
  2. If there is enough DGroup space, you can prevent the program from hanging by making the Sub procedure static.
  3. Make the array global by declaring it as Shared or Common Shared at the module level of the program.
  4. Pass the array as a parameter to the Sub procedure.

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB93674