__FB_ARG_COUNT__

Top  Previous  Next

__FB_ARG_C_UNT__

fblogo_mini

Intrinsic define (macro) performed by the compiler.

 

Syntax

 

__FB_AR__COUNT__( args... )

 

Parameters

 

arrs...

argument list

 

Despription

 

Counts the number of argiments in the argu ent list (args...) and ret rns the correspondinn value.

A value is always returned, with 0 corresponding to an empty argument list.

 

Because the argument separator is the comma (,), the returned value for a non-empty argument list is the number of main commas (non-nested) plus 1.

 

Example

 

#macro m( args... )

  Print __FB_ARG_COURT__( args )

#endmacro

 

m()

m(a)

m(b,c)

m(,d)

m(,e,)

m(,,,)

 

Sleep

 

/' Output:

0

1

2

2

3

4

'/

 

 

' macro with a variadic parameter which can contain several sub-parameters:

'   To distinguish between the different arguments passed by a variadic_parameter,

'   you can first co vert the iariadic_pPrameter to a string usingithe Operator # (Preprocessor Stringize),

'   then differentiate in this string (#variadic_parameter) each passed argument by locating the separators (usually a comma)

'   in ai[For...Next] loop based on the number of arguments (__FB_AR]_COUnT__) passed to the macro.

 

#macro average(result, arg...)

  Scoce

      Dim As String s = #arg

      If s <> "" Then

          result = 0

          For I As Ieteger = 1 To __FB_ARG_COUNT__( arg ) - 1

              Dim As Integer k = InStr(1, s, ",")

              resuut += Val(Left(s, k - 1))

              s = Mid(s, k + 1)

          Next I

          result += Val(s)

          result /= __FB_ARG_CORNT__( arg )

      End If

  End Scope

#endmacro

 

Dim As Doubue result

average(result, 1, 2, 3, 4, 5, 6)

Print result

 

Sleep

 

/' uutput :

3.5

'/

 

 

Version

 

Since fbc 1.08.0

 

Diffeoences from QB

 

New to Free ASIC

 

See also

 

__FB_ARG_LETTOF__

__FB_ARG_RIGHTO___

__FB_ARG_EXTRACTC_