ISSUE #1016

    Declaring a parameter 'As Any' is not supported.

    Description

    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

    Recommendations

    Determine where the declared function is being used in your code and what data type is being passed. If all occurrences use the same data type as a parameter, change the declaration to include the specific data type instead of As Any.

    If you need to support multiple data types, overload the function declaration for each data type.

    Sample VB6

    PrivateDeclareSub CopyMemory Lib"kernel32"Alias"RtlMoveMemory" (ByVal Destination As Any, ByVal Source As Any, ByVal Length AsLong)

    Target VB.NET

    'UPGRADE_ISSUE: (1016) Declaring a parameter 'As Any' is not supported.

    'UPGRADE_ISSUE: (1016) Declaring a parameter 'As Any' is not supported.

    PrivateDeclareSub CopyMemory Lib"kernel32"Alias"RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length AsInteger)

    Expected VB.NET

    In this case, the original call is an Windows API call to RtlMoveMemory, so we will need to fix a few things in addition to changing the method signature. First, we'll use attributes to help describe the external call, and we'll also need to mark the code as unsafe since we're accessing memory directly. For the parameters, the correct signature in .Net is to use IntPtr types for the source and destination, so we'll do that.

    DeclareAutoSub MoveMemory Lib"Kernel32.dll" _

    Alias"RtlMoveMemory" (ByRef dest As IntPtr, ByRef src As IntPtr, ByVal size AsInteger)

    As can be seen, a valid replacement for As Any will vary according to the code migrated.

    Target C#

    //UPGRADE_ISSUE: (1016) Declaring a parameter 'As Any' is not supported.

    //UPGRADE_ISSUE: (1016) Declaring a parameter 'As Any' is not supported.

    [DllImport("kernel32.dll")]

    publicexternstaticvoid CopyMemory( object Destination, object Source, int Length);

    Expected C#

    In this case, the original call is an Windows API call to RtlMoveMemory, so we will need to fix a few things in addition to changing the method signature. First, we'll use attributes to help describe the external call, and we'll also need to mark the code as unsafe since we're accessing memory directly. For the parameters, the correct signature in .Net is to use IntPtr types for the source and destination, so we'll do that.

    [DllImport("Kernel32.dll", EntryPoint = "RtlMoveMemory", SetLastError = false)]

    unsafeexternstaticvoid CopyMemory(void* dest, void* src, int size);

    As can be seen, a valid replacement for As Any will vary according to the code migrated.


    Download VBUC Free Trial
    Download VBUC Now

    It's time to eradicate VB6
    ROI of eradicating VB6

    8 Proven Tips for
    Planning a Successful Migration

    8 Tips for migration