Source code below was created in 2008 and it is still being used today and it is now a Trading Blox function: GetFieldCount()

 

Custom function Field_Count returns the number of populated fields in a string where each field in the string is separated by a comma.  If the string is empty and has a length equal to zero, or only contains the comma, the result returned will be zero.  If there is one field and one comma, the return is one.  Two fields and two commas returns two, etc.

Example:

'  ==============================================================
'  FUNCTION NAME: Field_Count
'  ==============================================================
'   DESCRIPTION:  This function returns the number of comma
'                 delimited fields in the passed string variable.
'   USE:
'      When a count of the number of comma separated values is
'      needed before the GetField functions is used.  
'   CODE FUNCTION CALL:
'     Function_Result = Script.Execute( "Field_Count", _
'                                        sAnyStringFieldGroup )
'        OR
'     PRINT Script.Execute( "Field_Count", sAnyStringFieldGroup )
'  --------------------------------------------------------------
'     FUNCTION START - Field_Count
'  --------------------------------------------------------------
'  Function Parameter Variables
VARIABLES: String_Fields_fc                 Type: String
'  Function Working Variables
VARIABLES: BeginPtr_fc, Field_Count_fc       Type: Integer
VARIABLES: EndPtr_fc, String_Length_fc       Type: Integer
'  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'  Assign ParameterList Items to Parameter Variables
'  so that Code is Self-Documenting, and so users can
'  easily see parameter requirements.
String_Fields_fc = script.stringParameterList[1] '  STRING
'  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'  Determine the Size of the String
String_Length_fc = Len(String_Fields_fc)
 
'  When there is enough Characters,...
If String_Length_fc > 0 THEN
 
  BeginPtr_fc = 1     '  Start at the first character
  Field_Count_fc = 1   '  No Delimiters Found Indicate only 1 Field
 
  ' Look at each character in the string
  For EndPtr_fc = 1 TO String_Length_fc
 
    '  If the Character is a Delimiter,...
    If FindString( mid(String_Fields_fc, EndPtr_fc, 1), "," ) > -1 THEN
        ' Count the field
        Field_Count_fc = Field_Count_fc + 1
       
        '  Adjust the Pointer's Character Location
        BeginPtr_fc = EndPtr_fc + 1
    ENDIF
  Next
ELSE  
  '  Empty String Has No Fields
  Field_Count_fc = 0
ENDIF      
'  Field_Count_fc Shows the number of Fields found
script.SetReturnValue( Field_Count_fc )   '  Return Function Value
'  --------------------------------------------------------------
'  Field_Count -  FUNCTION END
'  ==============================================================

 

 


Created with Help & Manual 7 and styled with Premium Pack Version 2.80 © by EC Software