Microsoft KB Archive/827048

= You receive a &quot;Not declared&quot; error message in the Task List window =

Article ID: 827048

Article Last Modified on 11/26/2007

-

APPLIES TO


 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-





SYMPTOMS
If you try to use certain Microsoft Visual Basic .NET or Microsoft Visual Basic 2005 functions (such as the Len function and the Mid function), you may receive error messages in the Task List window that are similar to the following error message:

Name ' ' not declared.

Note  is a placeholder for the name of the function that you try to use.

The function that you try to use is underlined in your code. The syntax tips are not displayed for this function.



CAUSE
This problem occurs because the &quot;Microsoft.VisualBasic&quot; namespace that the functions are declared in is not imported to your file or to your project. Also, the functions are not fully qualified with the name of the namespace that they are declared in. Therefore, Microsoft Visual Studio .NET or Microsoft Visual Studio 2005 and Microsoft IntelliSense do not recognize the functions.

Note Visual Studio .NET or Visual Studio 2005 automatically imports the &quot;Microsoft.VisualBasic&quot; namespace to all the Visual Studio .NET projects. However, you may prevent Visual Studio .NET or Visual Studio 2005 from automatically importing this namespace by using macros.



RESOLUTION
To resolve this problem for the Len function, Microsoft recommends that you use the Length property of the String class instead of using the Len function. To resolve this problem for the Mid function, Microsoft recommends that you use the Substring method of the String class instead of using the Mid function. To resolve this problem without using the String class, use fully-qualified function names in your code or import the namespace that the functions are declared in.

Note The following steps are based on the sample in the &quot;More Information&quot; section of this article. Therefore, the code and the file names in these steps may differ from your code and your file names.

Use the Length Property and the Substring Method
  In Form1.vb, locate the following code: Length = Len(MyString)   Replace the code that you located in step 1 with the following code: Length = MyString.Length   In Form1.vb, locate the following code: Fragment = Mid(MyString, 1, 4)   Replace the code that you located in step 3 with the following code: Fragment = MyString.Substring(0, 4)

There is no error message in the Task List window. Len and Mid are not underlined in your code.  On the Debug menu, click Start to run your application.

You receive a message that contains the following text:

5

 Click OK to dismiss this message.

You receive a message that contains the following text:

Hell

</li> Click OK to dismiss this message.</li></ol>

Use Fully-Qualified Function Names
<ol> In your code, replace all instances of Len with Microsoft.VisualBasic.Len.</li> In your code, replace all instances of Mid with Microsoft.VisualBasic.Mid.

There is no error message in the Task List window. Len and Mid are not underlined in your code.</li>  Position your pointer after the opening parenthesis in the following statement: Length = Microsoft.VisualBasic.Len(MyString) </li> Point to IntelliSense on the Edit menu, and then click Parameter Info.

A syntax tip is displayed.</li></ol>

Import the &quot;Microsoft.VisualBasic&quot; Namespace
You can import the &quot;Microsoft.VisualBasic&quot; namespace to your file or to your project.

Import the Microsoft.VisualBasic Namespace to Your File
<ol>  Add the following statement to the beginning of the Form1.vb file: Imports Microsoft.VisualBasic There is no error message in the Task List window. Len and Mid are not underlined in your code. </li>  Position your pointer after the opening parenthesis in the following statement: Length = Len(MyString) </li> Point to IntelliSense on the Edit menu, and then click Parameter Info.

A syntax tip is displayed.</li></ol>

Import the &quot;Microsoft.VisualBasic&quot; Namespace to Your Project
<ol> In Solution Explorer, right-click FuncDemo, and then click Properties.</li> In the left pane of the FuncDemo Property Pages dialog box, click Imports.</li> In the Namespace text box, type Microsoft.VisualBasic .</li> Click Add Import, and then click OK.

There is no error message in the Task List window. Len and Mid are not underlined in your code.</li>  Position your pointer after the opening parenthesis in the following statement: Length = Len(MyString) </li> Point to IntelliSense on the Edit menu, and then click Parameter Info.

A syntax tip is displayed.</li></ol>

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

Steps to Reproduce the Problem
<ol> Start Visual Studio .NET or Visual Studio 2005.</li> Create a Microsoft Windows application by using Visual Basic .NET or Visual Basic 2005. Name your application FuncDemo.

By default, Form1 is created.</li> <li> Add the following code to the OnLoad method of Form1: Dim MyString As String MyString = &quot;Hello&quot;

Dim Length As Integer Length = Len(MyString) MessageBox.Show(Length)

Dim Fragment As String Fragment = Mid(MyString, 1, 4) MessageBox.Show(Fragment) You receive an error message in the Task List window that is similar to the error message that is mentioned in the &quot;Symptoms&quot; section of this article. Len and Mid are underlined in your code. </li> <li> Position your pointer after the opening parenthesis in the following statement: Length = Len(MyString) </li> <li>Point to IntelliSense on the Edit menu, and then click Parameter Info.

No syntax tip is displayed.</li></ol>

<div class="references_section">