Export (0) Print
Expand All
Expand Minimize

Declare statement does not support parameters of type As Any

Visual Studio .NET 2003

In Visual Basic 6.0, you could declare a reference to an external procedure with the Declare statement and specify As Any for the data type of an argument or return type. The As Any keyword disabled type checking and allowed any data type to be passed in or returned.

In Visual Basic .NET, the As Any keyword is no longer supported. To ensure type safety, you must specifically declare the data type of all arguments and return values.

For example, the following declaration accepted either a string or a long data type as the second argument:

' Visual Basic 6.0
Declare Function LoadCursor Lib "user32" Alias "LoadCursorA"(ByVal hInstance As Long, ByVal lpCursorName As Any) As Long

' After upgrade to Visual Basic .NET
' UPGRADE_ISSUE: Declaring a parameter 'As Any' is not supported.
Declare Function LoadCursor Lib "user32" Alias "LoadCursorA"(ByVal hInstance As Integer, ByVal lpCursorName As Any) As Integer

What to do next

  • Determine where the declared function is being used in your code and what data type is being passed. If all occurrences pass the same data type, change the declaration to include that data type instead of As Any:
    Declare Function LoadCursor Lib "user32" Alias "LoadCursorA"(ByVal hInstance As Integer, ByVal lpCursorName As String) As Integer
    
  • If you need to support multiple data types, create an overloaded version of the declaration for each data type:
    Declare Function LoadCursor Lib "user32" Alias "LoadCursorA"(ByVal hInstance As Integer, ByVal lpCursorName As String) As Integer
    Declare Function LoadCursor Lib "user32" Alias "LoadCursorA"(ByVal hInstance As Integer, ByVal lpCursorName As Integer) As Long
    

See Also

Declaration Syntax Changes in Visual Basic

Show:
© 2014 Microsoft