ANY


The Any keyword is used as a placeholder for a type or value in various ways.

Syntax:
Dim identifier As Any Pointer|Ptr
or
Declare Sub|Function identifier ( Byref identifier As Any [ , ... ] )
or
Dim identifier(Any [, Any...]) As DataType
or
[ Declare ] { Sub | Function } proc_name ( param(Any [, Any...]) As DataType )
or
Dim identifier As DataType = Any
or
New DataType ( Any )
or
New(address) DataType [count] { Any }
or
Instr|InstrRev ( identifier, Any substring )
or
Procptr ( identifier, [Virtual] Any )

Description:
Examples:
Declare Sub echo(ByVal x As Any Ptr) '' echo will accept any pointer type

Dim As Integer a(0 To 9) = Any '' this variable is not initialized
Dim As Double  d(0 To 4)

Dim p As Any Ptr

Dim pa As Integer Ptr = @a(0)
Print "Not initialized ";
echo pa       '' pass to echo a pointer to integer

Dim pd As Double Ptr = @d(0)
Print "Initialized ";
echo pd       '' pass to echo a pointer to double

p = pa     '' assign to p a pointer to integer
p = pd     '' assign to p a pointer to double      

Sleep

Sub echo (ByVal x As Any Ptr)
    Dim As Integer i
    For i = 0 To 39
        'echo interprets the data in the pointer as bytes
        Print Cast(UByte Ptr, x)[i] & " ";
    Next
    Print
End Sub


'Example of ANY disabling the variable type checking
Declare Sub echo (ByRef a As Any) '' ANY disables the checking for the type of data passed to the function

Dim x As Single
x = -15
echo x                  '' Passing a single to a function that expects an integer. The compiler does not complain!!            
Sleep

Sub echo (ByRef a As Integer)
  Print Hex(a)        
End Sub


Dim a(Any) As Integer ' 1-dimensional dynamic array
Dim b(Any, Any) As Integer ' 2-dimensional dynamic array
Dim c(Any, Any, Any) As Integer ' 3-dimensional dynamic array
' etc.

' Further Redims or array accesses must have a matching amount of dimensions
ReDim a(0 To 1)
ReDim b(1 To 10, 2 To 5)
ReDim c(0 To 9, 0 To 5, 0 To 1)


Dialect Differences:
Differences from QB:
See also:
Back to Procedures
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode