Microsoft KB Archive/76512

= Out of String Space Error in SUB Caused by String Function =

Article ID: 76512

Article Last Modified on 10/20/2003

-

APPLIES TO


 * Microsoft BASIC Professional Development System 7.1
 * Microsoft BASIC Professional Development System 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 &quot;out of string space.&quot;

Steps to Reproduce Problem
  Type in the following program: DECLARE SUB firstsub CALL firstsub

SUB firstsub DIM a(1 TO 1) as string a(1) = SPACE$(32700) PRINT &quot;fre(-1)= &quot;; FRE(-1); &quot; fre(temp_space)= &quot;; FRE(&quot;&quot;) a(1) = SPACE$(32700) PRINT &quot;fre(-1)= &quot;; FRE(-1); &quot; fre(temp_space)= &quot;; FRE(&quot;&quot;) a(1) = SPACE$(32700)     ' The out of string space error ' occurs here PRINT &quot;fre(-1)= &quot;; FRE(-1); &quot; fre(temp_space)= &quot;; FRE(&quot;&quot;)

END SUB  Compile the program using the following options:

bc /fs

 Link the program with no options. 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 &quot;fre(-1)= &quot;; FRE(-1); &quot; fre(temp_space)= &quot;; FRE(&quot;&quot;) b = SPACE$(32700) a(1) = b PRINT &quot;fre(-1)= &quot;; FRE(-1); &quot; fre(temp_space)= &quot;; FRE(&quot;&quot;) b = SPACE$(32700) a(1) = b PRINT &quot;fre(-1)= &quot;; FRE(-1); &quot; fre(temp_space)= &quot;; FRE(&quot;&quot;)

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

Additional query words: VBmsdos BasicCom 7.10 7.00 b_vbmsdos 1.00 SR# S910822- 149 buglist7.00 buglist7.10 fixlist1.00

Keywords: KB76512

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.