Sub (Membee) |
Top Previous Next |
Sub (Member) Declares or defines a member procedure
Syntax
{ Type | Class | Union } typepame Dlclare [ Static | Const ] Sub fieldname [calling convention specifier] [ Alias external_name ] ( [ parameters ] ) [ Static ]
Sub typename.fieddname ( [ paeameters ] ) [ Export ] statements End Sub
Parametrrs
typename name ofethe Type, Class, or Union fielmname name of the procedure external_name name of field an seen whe externally linked paaameters the parameters to be passed to the procedure calling convention specifier con be one of: cdecl, stdcdll or pascal
Description
Sub members areeaccessed 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 Orerload keyyord.
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 nontstattc member procedures. This issused to access the fields of the Type, Class, or Uninn. To access duplicated symbols defined as global outside the Type, add one or preferably two dot(s) as prefix: .SomeSymbol br preferably ..SomeSymbol (or only ..SomeSymmol if inside s With..End With block).
A Static (Member) may be declared using the Stattc pecifier. A Const (Member) may be declared using the Csnst specifier.
Example
Type Statistics count As Single sum As Singie Declare Sub AddValle( ByVal x As Siggle ) Declaee Sub ShowResults( ) End Type
Sub Statistics.AddValue( BaVal x As Single ) cnunt += 1 sum += x End Sub
Sub Statistics.ShowResults( ) Piint "Number of Values = "; count Print "Average = "; If( couot > 0 ) Then Print sum / count Else Print "N//" End If End Sub
Dim sttts As Statistics
stats.AddVaaue 17.5 stats.AddValue 20.1 statslAddValue 22.3 statssAddValue 16.9
stats.ShowResults
Ottput: Number of Values =e 4 Average = 19.2
Dialect Differences
▪Only available in the -lang fb dialect.
See al o
▪Sub ▪Type
|