Skip to content

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]

*or* Instr|InstrRev ( identifier, Any substring )

*or* Procptr ( identifier, [Virtual] Any )

`

Description

  • Pointers (1st syntax):
  • Byref parameters (2nd syntax):
  • Array dimensions (3rd/4th syntax):
  • Initialization (5th/6th/7th syntax):
  • Instr/InstrRev (8th syntax):
  • Procptr (9th syntax):

Examples

start GeSHi

vb
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

end GeSHi

start GeSHi

vb
'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

end GeSHi

start GeSHi

vb
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)

end GeSHi

Dialect Differences

Differences from QB

  • Pointers and initializers are new to FreeBASIC.

See also

  • Dim
  • Declare

Back to DocToc

Translated from FreeBASIC official docs. Contact us for removal if infringed.
FreeBASIC is an open-source project, not affiliated with Microsoft