Question
Array and CFC question
Hi!
Ok, here's what I'm trying. I have and array that I'm storing all the letters
of the alphabet, and I also want to count how many times a users 1st letter
of their last name match that letter in the alphabet. I created the array
as follows:
<cfset alphaList=arraynew(2)>
<cfset alphaListLoop="A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z">
<cfset alphaLoopCount=1>
<cfloop list="#alphaListLoop#" delimiters="," index="i">
<cfset alphaList[#alphaLoopCount#][1]=#i#>
<!--- send to udf to count each letter occurance and assign
to variable --->
<cfinvoke component="components.reccount" method="getinfo"
returnvariable="result">
<cfinvokeargument name="alpha" value="#i#">
</cfinvoke>
<cfset alphaList[#alphaLoopCount#][2]=#result#>
<cfset alphaLoopCount=alphaLoopCount+1>
</cfloop>
So each letter is assigned, and the automatic count is set to 0.
The problem comes when I'm using the <cfinvoke>, here's the code for that:
<cfcomponent displayname="reccount" hint="Counts all records with a specific
1st letter">
<!--- This function retrieves all customers from the database --->
<cffunction name="getinfo"
hint="Counts records" returntype="numeric" output="no">
<cfargument name="alpha" required="yes" type="string">
<cfset var result = 0>
<cftry>
<cfquery name="CountRec" datasource="SalleBoise">
SELECT Cust_Name FROM inforeq
</cfquery>
<cfloop query="CountRec">
<cfset tmpLname=(findnocase(" ",#CountRec.Cust_Name#) + 1)>
<cfset tmpLname2=left(mid(LastRegistered.Cust_Name,tmpLname,(tmpLname-1)),1)>
<cfif tmpLname2 eq #arguments.alpha#>
<cfset result=result + 1>
</cfif>
</cfloop>
<cfcatch type="any">
<cfset result = false>
</cfcatch>
</cftry>
<cfreturn result />
</cffunction>
</cfcomponent>
When I try to run the code, I'm getting:
Complex object types cannot be converted to simple values.
The expression has requested a variable or an intermediate expression result
as a simple value, however, the result cannot be converted to a simple value.
Simple values are strings, numbers, boolean values, and date/time values.
Queries, arrays, and COM objects are examples of complex values.
Where did I go wrong?????
Ok, here's what I'm trying. I have and array that I'm storing all the letters
of the alphabet, and I also want to count how many times a users 1st letter
of their last name match that letter in the alphabet. I created the array
as follows:
<cfset alphaList=arraynew(2)>
<cfset alphaListLoop="A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z">
<cfset alphaLoopCount=1>
<cfloop list="#alphaListLoop#" delimiters="," index="i">
<cfset alphaList[#alphaLoopCount#][1]=#i#>
<!--- send to udf to count each letter occurance and assign
to variable --->
<cfinvoke component="components.reccount" method="getinfo"
returnvariable="result">
<cfinvokeargument name="alpha" value="#i#">
</cfinvoke>
<cfset alphaList[#alphaLoopCount#][2]=#result#>
<cfset alphaLoopCount=alphaLoopCount+1>
</cfloop>
So each letter is assigned, and the automatic count is set to 0.
The problem comes when I'm using the <cfinvoke>, here's the code for that:
<cfcomponent displayname="reccount" hint="Counts all records with a specific
1st letter">
<!--- This function retrieves all customers from the database --->
<cffunction name="getinfo"
hint="Counts records" returntype="numeric" output="no">
<cfargument name="alpha" required="yes" type="string">
<cfset var result = 0>
<cftry>
<cfquery name="CountRec" datasource="SalleBoise">
SELECT Cust_Name FROM inforeq
</cfquery>
<cfloop query="CountRec">
<cfset tmpLname=(findnocase(" ",#CountRec.Cust_Name#) + 1)>
<cfset tmpLname2=left(mid(LastRegistered.Cust_Name,tmpLname,(tmpLname-1)),1)>
<cfif tmpLname2 eq #arguments.alpha#>
<cfset result=result + 1>
</cfif>
</cfloop>
<cfcatch type="any">
<cfset result = false>
</cfcatch>
</cftry>
<cfreturn result />
</cffunction>
</cfcomponent>
When I try to run the code, I'm getting:
Complex object types cannot be converted to simple values.
The expression has requested a variable or an intermediate expression result
as a simple value, however, the result cannot be converted to a simple value.
Simple values are strings, numbers, boolean values, and date/time values.
Queries, arrays, and COM objects are examples of complex values.
Where did I go wrong?????
