You receive a "Not declared" error message in the Task List window

Article translations Article translations
Article ID: 827048 - View products that this article applies to.
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

On This Page

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 'Function Name' not declared.
Note Function Name 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 "Microsoft.VisualBasic" 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 "Microsoft.VisualBasic" 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 "More Information" 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

  1. In Form1.vb, locate the following code:
    Length = Len(MyString)
  2. Replace the code that you located in step 1 with the following code:
    Length = MyString.Length
  3. In Form1.vb, locate the following code:
    Fragment = Mid(MyString, 1, 4)
  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.
  5. On the Debug menu, click Start to run your application.

    You receive a message that contains the following text:
    5
  6. Click OK to dismiss this message.

    You receive a message that contains the following text:
    Hell
  7. Click OK to dismiss this message.

Use Fully-Qualified Function Names

  1. In your code, replace all instances of Len with Microsoft.VisualBasic.Len.
  2. 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.
  3. Position your pointer after the opening parenthesis in the following statement:
    Length = Microsoft.VisualBasic.Len(MyString)
  4. Point to IntelliSense on the Edit menu, and then click Parameter Info.

    A syntax tip is displayed.

Import the "Microsoft.VisualBasic" Namespace

You can import the "Microsoft.VisualBasic" namespace to your file or to your project.

Import the Microsoft.VisualBasic Namespace to Your File

  1. 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.
  2. Position your pointer after the opening parenthesis in the following statement:
    Length = Len(MyString)
  3. Point to IntelliSense on the Edit menu, and then click Parameter Info.

    A syntax tip is displayed.

Import the "Microsoft.VisualBasic" Namespace to Your Project

  1. In Solution Explorer, right-click FuncDemo, and then click Properties.
  2. In the left pane of the FuncDemo Property Pages dialog box, click Imports.
  3. In the Namespace text box, type Microsoft.VisualBasic.
  4. 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.
  5. Position your pointer after the opening parenthesis in the following statement:
    Length = Len(MyString)
  6. Point to IntelliSense on the Edit menu, and then click Parameter Info.

    A syntax tip is displayed.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Problem

  1. Start Visual Studio .NET or Visual Studio 2005.
  2. Create a Microsoft Windows application by using Visual Basic .NET or Visual Basic 2005. Name your application FuncDemo.

    By default, Form1 is created.
  3. Add the following code to the OnLoad method of Form1:
    Dim MyString As String
    MyString = "Hello"
    
    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 "Symptoms" section of this article. Len and Mid are underlined in your code.
  4. Position your pointer after the opening parenthesis in the following statement:
    Length = Len(MyString)
  5. Point to IntelliSense on the Edit menu, and then click Parameter Info.

    No syntax tip is displayed.

REFERENCES

For more information, visit the following Microsoft Web sites:
String Class
http://msdn2.microsoft.com/en-us/library/system.string(vs.71).aspx
Task List Window
http://msdn2.microsoft.com/en-us/library/170k1bbs(vs.71).aspx
Microsoft.VisualBasic Namespace
http://msdn2.microsoft.com/en-us/library/microsoft.visualbasic(vs.71).aspx
5.2 Imports Statement
http://msdn2.microsoft.com/en-us/library/ms525365.aspx
Namespaces
http://msdn2.microsoft.com/en-us/library/zt9tafza(vs.71).aspx
Using IntelliSense
http://msdn2.microsoft.com/en-us/library/hcw1s69b(vs.71).aspx
Setting Visual Basic Project Properties
http://msdn2.microsoft.com/en-us/library/Aa301634(VS.71).aspx

Properties

Article ID: 827048 - Last Review: February 27, 2014 - Revision: 2.7
APPLIES TO
  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
Keywords: 
kbnosurvey kbarchive kbvs2005swept kbvs2005applies kbideproject kbnamespace kbprogramming kbprb KB827048

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com