Returns the number of instances of a specified value in a list. The underlying search that finds the instances is case-sensitive.
See also ListValueCountNoCase.
ListValueCount(list, value [, delimiters ])
A list or the name of a list that is to be searched.
The string or number that the function is to find and count.
Optional. Specify the character(s) used to delimit elements in the list. The default is a comma ( , ).
<!--- This example uses ListValueCount to see how many employees are in a department ---> <HTML> <HEAD> <TITLE>ListValueCount Example</TITLE> </HEAD> <BASEFONT FACE="Arial, Helvetica" SIZE=2> <BODY bgcolor="#FFFFD5"> <CFQUERY Name="SearchByDepartment" DATASOURCE="HRApp"> SELECT Department_ID FROM Employees </CFQUERY> <H3>ListValueCount Example</H3> <P>This example uses ListValueCount to see how many employees are in a department. <FORM ACTION="listvaluecount.cfm" METHOD="POST"> <P>Select a department:</P> <SELECT NAME="departmentName"> <OPTION VALUE="1"> Training </OPTION> <OPTION VALUE="2"> Marketing </OPTION> <OPTION VALUE="3"> HR </OPTION> <OPTION VALUE="4"> Sales </OPTION> </SELECT> <INPUT TYPE="Submit" NAME="Submit" VALUE="Search Employee List"> </FORM> <!--- wait to have a string for searching defined ---> <CFIF IsDefined("form.Submit") and IsDefined("form.departmentName")> <CFSET myList = ValueList(SearchByDepartment.Department_ID)> <CFSET numberInDepartment = ListValueCount(myList, form.departmentName)> <CFOUTPUT> <P>There are #numberInDepartment# people in </CFOUTPUT> <CFIF FORM.DepartmentName Is "1"> Training. <CFELSEIF FORM.DepartmentName Is "2"> Marketing. <CFELSEIF FORM.DepartmentName Is "3"> HR. <CFELSEIF FORM.DepartmentName Is "4"> Sales. <CFELSE> Try again. </CFIF> </CFIF> </BODY> </HTML>