Out of String Space Error in SUB Caused by String Function (76512)



The information in this article applies to:

  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.1
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0

This article was previously published under Q76512

SYMPTOMS

In a Basic .EXE program compiled for far strings, if you use Basic string functions such as LEFT$ or SPACE$ in an assignment to a string array element within a Basic SUB or FUNCTION, the temporary string space allocated to perform the assignment(s) is not released until you exit the SUB or FUNCTION.

WORKAROUND

To work around the problem, you can assign the string returned from the Basic string function to a simple string variable, then assign that string variable to the string array element.

Note that this problem only occurs in a program compiled for far strings (with BC /Fs), and not in the QBX.EXE environment or a program compiled for near strings.

STATUS

Microsoft has confirmed this to be a bug in Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2, versions 7.0 and 7.1. This problem was corrected in Microsoft Visual Basic version 1.0 for MS-DOS.

MORE INFORMATION

When using a string function such as SPACE$, temporary memory is used to store the intermediate result. Normally this memory would be released, and the next time a call is made to a string function the same amount of memory will be available. In a compiled program using far strings (BC /Fs), this temporary memory does not get released when the result of a string function is assigned to a string array element within a SUB or FUNCTION. This can cause the error message "out of string space."

Steps to Reproduce Problem

  1. Type in the following program:
    DECLARE SUB firstsub ()
    CALL firstsub
    
    SUB firstsub
    DIM a(1 TO 1) as  string
    a(1) = SPACE$(32700)
    PRINT "fre(-1)= "; FRE(-1); " fre(temp_space)= "; FRE("")
    a(1) = SPACE$(32700)
    PRINT "fre(-1)= "; FRE(-1); " fre(temp_space)= "; FRE("")
    a(1) = SPACE$(32700)      ' The out of string space error
                     ' occurs here
    PRINT "fre(-1)= "; FRE(-1); " fre(temp_space)= "; FRE("")
    
    END SUB
    						
  2. Compile the program using the following options:

    bc /fs

  3. Link the program with no options.
  4. When the program gets to the third SPACE$ it will run out of string space because all of the temporary string space has been used.

Workaround

DECLARE SUB firstsub ()
CALL firstsub

SUB firstsub
DIM a(1 TO 1) as  string
DIM b as string

b = SPACE$(32700)
a(1) = b
PRINT "fre(-1)= "; FRE(-1); " fre(temp_space)= "; FRE("")
b = SPACE$(32700)
a(1) = b
PRINT "fre(-1)= "; FRE(-1); " fre(temp_space)= "; FRE("")
b = SPACE$(32700)
a(1) = b
PRINT "fre(-1)= "; FRE(-1); " fre(temp_space)= "; FRE("")

END SUB
				
Compile and link using the same options as above. This program will release the temporary space after each use of SPACE$.

Modification Type:MajorLast Reviewed:10/20/2003
Keywords:KB76512