Microsoft KB Archive/814606

= BUG: &quot;Out of memory&quot; error if you sse the GetSetting function to retrieve an empty string from the registry in Visual Basic .NET and in Visual Basic 6.0 =

Article ID: 814606

Article Last Modified on 5/11/2007

-

APPLIES TO


 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



SYMPTOMS
If you store an empty string in the registry by using the SaveSetting function in Microsoft Visual Basic .NET, and then you retrieve the same empty string value by using the GetSetting function in Microsoft Visual Basic 6.0, you may receive the following error message:

Run-time error '7': Out of memory



CAUSE
The SaveSetting function creates a registry key with the value provided as a parameter. The Visual Basic .NET SaveSetting function writes a value of zero bytes in the registry to represent an empty string. However, the Visual Basic 6.0 SaveSetting function or Registry Editor stores a two-byte NULL character in the registry for the empty string. The Visual Basic 6.0 GetSetting function also expects a two-byte NULL character for the empty string value. An error occurs while the application reads the string value from the registry, because the Visual Basic 6.0 GetSetting function receives zero-byte data instead of a two-byte NULL character.



WORKAROUND
To work around this problem, pass a vbNullChar as a parameter for the key value to the Visual Basic .NET SaveSetting function, instead of passing an empty string.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.



Steps to Reproduce the Behavior
 Open Microsoft Visual Studio .NET. On the File menu, point to Open, and then click Project. Under Project Types, select Visual Basic Projects. Under Templates, select Console Application. Name the project TestSaveSetting .  Replace the code in the Module1.vb file with the following code: Module Module1 Sub Main 'Save the empty string in registry SaveSetting(&quot;myAppName&quot;, &quot;mySection&quot;, &quot;myKey&quot;, &quot;&quot;) Dim testString As String

'Retrieve the empty string from registry testString = GetSetting(&quot;myAppName&quot;, &quot;mySection&quot;, &quot;myKey&quot;) Console.WriteLine(&quot;Retrieved Registry string value successfully&quot;) End Sub End Module </li> On the Debug menu, click Start to run the application.

The application creates the registry entry by using the SaveSetting function of Visual Basic .NET.</li> Open Visual Basic 6.0.</li> On the File menu, click New Project.</li> In the New Project window, select Standard Exe, and then click OK.

By default, Form1 is created.</li> In the toolbox, double-click CommandButton.</li>  On Form, double-click Command1, and then add the following code to Command1_Click event: Dim strTest As String strTest = GetSetting(&quot;myAppName&quot;, &quot;mySection&quot;, &quot;myKey&quot;) </li> On the Run menu, click Start to run the application.</li> Click Command1.</li></ol>

Keywords: kbvs2005swept kbvs2005doesnotapply kbvs2002sp1sweep kbregistry kbmigration kbstring kbbug KB814606

-

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

© Microsoft Corporation. All rights reserved.