You receive a "Not declared" error message in the Task List window (827048)
The information in this article applies to:
- Microsoft Visual Basic 2005
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic .NET (2002)
SYMPTOMSIf
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. CAUSEThis 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.RESOLUTIONTo
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- 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 - Click OK to dismiss this
message.
Use Fully-Qualified Function Names- In your code, replace all instances of Len
with Microsoft.VisualBasic.Len.
- 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. - Position your pointer after the opening parenthesis in the
following statement:
Length = Microsoft.VisualBasic.Len(MyString) - Point to IntelliSense on the
Edit menu, and then click Parameter
Info.
A syntax tip is displayed.
Import the "Microsoft.VisualBasic" NamespaceYou can import the "Microsoft.VisualBasic" namespace to your file
or to your project. Import the Microsoft.VisualBasic Namespace to Your File- 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. - Position your pointer after the opening parenthesis in the
following statement:
Length = Len(MyString) - 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- In Solution Explorer, right-click
FuncDemo, and then click
Properties.
- In the left pane of the FuncDemo Property
Pages dialog box, click Imports.
- In the Namespace
text box, type Microsoft.VisualBasic.
- 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. - Position your pointer after the opening parenthesis in the
following statement:
Length = Len(MyString) - Point to IntelliSense on the
Edit menu, and then click Parameter
Info.
A syntax tip is displayed.
STATUS This
behavior is by design.REFERENCESFor more information, visit the following Microsoft Web
sites:
Modification Type: | Minor | Last Reviewed: | 10/3/2006 |
---|
Keywords: | kbvs2005swept kbvs2005applies kbIDEProject kbNameSpace kbProgramming kbprb KB827048 kbAudDeveloper |
---|
|