SUB (Member)


Declares or defines a member procedure.

Syntax:
{ Type | Class | Union } typename
declare [ static | const ] Sub fieldname [calling convention specifier] [ alias external_name ] ( [ parameters ] ) [ Static ]
End { Type | Class | Union }

Sub typename.fieldname ( [ parameters ] ) [ Export ]
statements
End Sub

Parameters:
typename
name of the Type, Class, or Union
fieldname
name of the procedure
external_name
name of field as seen when externally linked
parameters
the parameters to be passed to the procedure
calling convention specifier
can be one of: Cdecl, Stdcall or Pascal

Description:
Sub members are accessed with Operator . (Member access) or Operator -> (Pointer to member access) to call a member procedure and may optionally accept parameters either byval or byref. typename be overloaded without explicit use of the Overload keyword.

typename is the name of the type for which the Sub method is declared and defined. Name resolution for typename follows the same rules as procedures when used in a Namespace.

A hidden this parameter having the same type as typename is passed to non-static member procedures. this is used to access the fields of the Type, Class, or Union.
To access duplicated symbols defined outside the Type, add one (or two) dot(s) as prefix: .SomeSymbol (or ..SomeSymbol if inside a With..End With block).

A Static (Member) may be declared using the Static specifier. A Const (Member) may be declared using the Const specifier.

Examples:
Type Statistics
  count As Single
  sum As Single
  Declare Sub AddValue( ByVal x As Single )
  Declare Sub ShowResults( )
End Type

Sub Statistics.AddValue( ByVal x As Single )
  count += 1
  sum += x
End Sub

Sub Statistics.ShowResults( )
  Print "Number of Values = "; count
  Print "Average          = ";
  If( count > 0 ) Then
    Print sum / count
  Else
    Print "N/A"
  End If
End Sub

Dim stats As Statistics

stats.AddValue 17.5
stats.AddValue 20.1
stats.AddValue 22.3
stats.AddValue 16.9

stats.ShowResults

Output:
Number of Values =  4
Average          =  19.2


Dialect Differences:
See also:
Back to User Defined Types
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode