DCount

The DCount function (Delimiter Count) may be used to determine the number of occurrences of a specified delimiter within a string, or a string variable. The command will also add 1 to the count to actually represent the number of values or fields stored within the string variable. This makes the DCount command really return the number of available fields in the record so that extra logic is not necessary when determining the length of a loop structure used to manipulate the contents of the string.

Group: Dynamic Array Extensions


Syntax: vNbr = DCount(vVAR, vDELIM)

vNbr        (Variant) is a number of delimiters found in the variable plus 1.

vVAR       (Variant) is the string value to be evaluated

vDELIM   (Variant) is a specified delimiter character, or multi-character string to count; e.g., to count dynamic array delimiters use Chr(1), Chr(2), Chr(3).

Example:

Dim nNbr As Long

Dim sNames As String

sNames = "John&Mike&Albert"

nNbr = DCount(sNames,Chr(1)) ' Nbr = 3

sNames = "&Mike&Albert"

nNbr = DCount(sNames,Chr(1)) ' Nbr = 3

sNames = "&Mike&"

nNbr = DCount(sNames,Chr(1)) ' Nbr = 3

Note that +1 has been added to the actual count of Chr(1) (represented here with a character ’&’) count of 2. Also note that just because the fields are empty, they are valid slots where data may be inserted.