Home > Software engineering >  VB6 can produce write the Sub As Any this kind of writing
VB6 can produce write the Sub As Any this kind of writing

Time:09-24

As Any in Declare sub see

Always wanted to know VB6 Sub can produce As Any one write this kind of method call


For example,

Sub Form1_Load

Dim ar1 (11) as long

Call QQQQ (ar1)

End Sub


Sub QQQQ (ar () As Any) 'excuse me is there a way to achieve this kind of writing you

End Sub

CodePudding user response:


Declare statement



Used in the module level statement to the dynamic link library (DLL) in the process of external reference,

Grammar 1

[Public | Private] Declare Sub name Lib "libname" [Alias "aliasname"] [] ([arglist])

Syntax 2

[Public | Private] Declare the Function name Lib "libname" [Alias "aliasname"] [() [arglist]] [As type]

The grammar of the Declare statement contains the following parts:

Part of the description
Public optional, for all module used to declare all the other processes can be used in the process,
Private optional, used to declare only contains the modules used in the process of the statement,
Sub optional (but Sub or Function needs to choose two), said that the process has no return value,
Function optional (but Sub or Function needs to choose two), said the process would return a can be used for the value of the expression,
Name required, any legal process, pay attention to the entrance of the dynamic link library (entry points) are case sensitive,
Lib required, indicate the dynamic link library containing the declaration process, or source code, all statements need Lib clause,
Libname required, containing the declaration process of dynamic link library name or code resource name,
Alias optional, says is called process in a dynamic link library (DLL) in the name of the other, when external procedure name and a key name repetition, you can use this parameter, when the process of dynamic link library with the same within the scope of the public variables, constants, or any other process at the same time, the name of the phase can also use the Alias, if a character in the process of the dynamic link library is not in conformity with the dynamic link library naming conventions, also can use Alias,
Aliasname optional, process of the dynamic link library or source code, if the first character is not a number sign (#), is aliasname in the dynamic link library name at the entrance of the process, if the first character is the (#), the subsequent characters must specify the serial number at the entrance of the process,
Arglist optional, representative calls the process need to pass the parameters of the variables,
Type optional, process the Function return value data types; Can be a Byte, Boolean, Integer, Long, Currency, Single, Double, Decimal (it is not supported), the Date, the String (only support variable-length) or the Variant, user-defined types, or object type,


Arglist parameters of syntax and grammar parts as follows:

[Optional] [ByVal | ByRef] [ParamArray] varname [(a)] [As type]

Part of the description
Optional Optional, said parameter is not required, if you use this option, by the subsequent parameters are required arglist is Optional, but must use the Optional keyword, if you use the ParamArray, no parameters can use the Optional,
ByVal optional, said that the parameters are passed by value,
ByRef said the parameter passed by address, ByRef is the default option of Visual Basic,
ParamArray Optional, only the last parameter for arglist, said the last argument is a Variant array of Optional elements, use ParamArray keyword can provide any number of parameters, ParamArray with ByVal keyword cannot, ByRef or Optional use together,
Varname required, representative to the parameters of the process variable names; Follow the standard variable naming conventions,
() an array variable is required, indicate the varname is an array,
Type is optional and passed to the parameters of the process data types; Can be a Byte, Boolean, Integer, Long, Currency, Single, Double, Decimal (it is not supported), the Date, the String (only support variable-length), Object, the Variant, user-defined types or Object type,


Description

For the Function process, process the data type of the determine its data type, the return value can be used after arglist As clause to specify the data type of Function return value, in arglist, can be used As clause to specify Any data type to the parameters of the process, not only can be specified for Any standard data type, can be specified As Any in the arglist type checking is forbidden, allowing arbitrary data type is passed to the process,

Empty parentheses indicate that the Sub process or Function has no parameters, and Visual Basic should ensure that won't pass any parameters, in the example below, the First without any arguments, if the First call USES the parameters, can produce error:

Declare Sub First Lib "MyLib" ()

If the parameter table, every time you call the process to check the number and type of parameters, in the example below, the First has a Long parameters:

Declare Sub First Lib "MyLib" (X As Long)

Note that in the parameters of the Declare statement in the table cannot have the long string; Only become long string to the process, set the long string can be used as process parameters, but before delivery has to be converted into variable-length string,

Note when invoked by the external process need a string value is 0, then use vbNullString constant, the constant and zero length string (" ") is not the same,

CodePudding user response:

Any in VB6 is used only for the API, the statement of the cannot be used in the custom declare variables in the parameters of the procedure or function type ,

The parameter type for Any API statement, generally means that the parameter value is a 32-bit pointer value,
In the call statement, usually in the form of a "variable reference" pass parameters; Or use ByVal Varptr (XXX) is passed to the API is used,

CodePudding user response:

The
refer to the original poster Bobogg response:
As Any in Declare in the sub see

Always wanted to know VB6 Sub can produce As Any one write this kind of method call
.

If you write that "standard DLL", and you can properly handle the incoming parameters, of course, also can produce this kind of method call,
  • Related