This function returns the number of comma delimited values in a text string.  When there are no values in the string function the return value will be 1.  One is returned because the function counts commas and adds 1 comma because the last value won't always be followed by a comma.  This process is shown in the examples below.

 

Often used for looping over the fields, using the GetField function.

 

Syntax:

count = GetFieldCount( stringValue )

 

Parameter:

Description:

stringValue

Comma delimited string

count

Number of comma delimited values

 

Example:

'  No Commas and no values
sStringRecord = ""
x = GetFieldCount(sStringRecord)
PRINT "sStringRecord : ", sStringRecord
PRINT " Return Count : ", x

Results:

sStringRecord :  

Return Count :  1  

Example:

'  When a String variable can be empty, consider this modification
'  No Commas and no values
sStringRecord = ""
x = Min(Len(Trim(sStringRecord)),GetFieldCount(sStringRecord))
PRINT "sStringRecord : ", sStringRecord
PRINT " Return Count : ", x

Results:

sStringRecord :  

Return Count :  0

Example:

'  No Comma After Last Value
sStringRecord = "S,10,20,30,40"
x = GetFieldCount(sStringRecord)
PRINT "sStringRecord : ", sStringRecord
PRINT " Return Count : ", x

Results:

sStringRecord :  S,10,20,30,40

Return Count :  5

Example:

'  Comma After Last Value
sStringRecord = "S,10,20,30,40,"
x = GetFieldCount(sStringRecord)
PRINT "sStringRecord : ", sStringRecord
PRINT " Return Count : ", x

Results:

sStringRecord :  S,10,20,30,40,

Return Count :  6

 

Links:

GetField, ReadLines, RemoveCommasBetweenQuote, RemoveNonDigits

See Also:

Data Groups and Types

 


Edit Time: 9/25/2017 09:09:58 AM


Topic ID#: 353

 

 

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