Claude, I’m not picking a fight but I don’t see how that answers my question at 
all. The good news is that I think you are very close to a solution, but you 
seem to have missed what I said.

Why do you have the function being defined within this query loop you refer to 
(in words, but don’t reflect in the code). Are you saying, perhaps, that some 
of the variables within the function are references to query variables? I don’t 
see that. It seems the UDF (user-defined function) is self-contained, and it 
operates on whatever is passed into it.

So I’ll ask again: why don’t you simply put this *definition* of the function 
OUTSIDE the loop and just *call the function from within the loop*, passing it 
the values within the loop on which you want to perform these calculations?

And your subject and initial question refer to this being about “dynamic 
naming” of the function, but your code below shows no such thing. When you said 
in your first note that you were trying to do that with “function 
getDistance#id#”, I wonder: were you trying that simply because you were 
getting the error about not being able to duplicate the function? Again, you 
don’t need to have the function being duplicated. 

Just move the function out of the loop and you should be all set. :-)

/charlie

 

From: cfaussie@googlegroups.com [mailto:cfaussie@googlegroups.com] On Behalf Of 
rai...@ozemail.com.au
Sent: Wednesday, March 25, 2015 11:49 PM
To: cfaussie@googlegroups.com
Subject: RE: [cfaussie] Help With Dynamic Naming A CfScript Function

 

This is the code I am using

 

/**

* Calculates distance between Latitude/Longitude points using haversine formula.

* 

 * @param lat1    latitude of first point (Required)

* @param lon1    longitude of first point (Required)

* @param lat2    latitude of second point (Required)

* @param lon2    longitude of second point (Required)

* @param units  Units for return value. Default is miles. (Optional)

* @return Returns numeric distance between the two points. Units varies, 
default is miles. 

 * @author Henry Ho (henryho...@gmail.com) 

 * @version 0, January 8, 2013 

 */

function getDistance(lat1, lon1, lat2, lon2, units = 'miles')

{

        // earth's radius. Default is miles.

        var radius = 3959;

        if (arguments.units EQ 'kilometers' )

                 radius = 6371;

        else if (arguments.units EQ 'feet')

                 radius = 20903520;

        

        var toRad = pi() / 180;

        var dLat = (lat2-lat1) * toRad;

        var dLon = (lon2-lon1) * toRad; 

        var a = sin(dLat/2)^2 + cos(lat1 * toRad) * cos(lat2 * toRad) * 
sin(dLon/2)^2; 

        var c = 2 * createObject("java","java.lang.Math").atan2(sqr(a), 
sqr(1-a));

        

        return radius * c;

}

 

 

Its wrapped inside a cfloop as I need to validate code received into our portal 
from mobile devices against data stored in the database hence the need to look 
around the data records from the query as often there will be more than 1 
records to test against

 

 

 

 

 

NB: TrackingCentral is now a registered product & services provider for the 
National Disability Insurance Scheme, under the category of Assisted Technology

 

Regards

 

Claude Raiola
Director
TrackingCentral Pty. Ltd

Free Call 1300 255 990

 

TrackingCentral_Logo

 

 

From: cfaussie@googlegroups.com [mailto:cfaussie@googlegroups.com] On Behalf Of 
Charlie Arehart
Sent: Thursday, 26 March 2015 1:26 PM
To: cfaussie@googlegroups.com
Subject: RE: [cfaussie] Help With Dynamic Naming A CfScript Function

 

Right, but why do you need the name of the function to be dynamic? Why isn’t it 
enough that you pass in args within the loop (and declare the function outside 
of it)?

/charlie

From: cfaussie@googlegroups.com [mailto:cfaussie@googlegroups.com] On Behalf Of 
rai...@ozemail.com.au
Sent: Wednesday, March 25, 2015 11:14 PM
To: cfaussie@googlegroups.com
Subject: RE: [cfaussie] Help With Dynamic Naming A CfScript Function

 

I am calculating distance between 2 sets of lon / lat and the information is 
dynamic so I need to capture the values of the dynamic data and compare them to 
the values stored in a database table of which there may been to be several 
records tested against the values in the dynamic data 

 

Eg 1 set of co ordinate received from a device in the field data is received by 
the listener and needs to be tested against co ordinates recorded in the 
database table of which there may be several records needing to be tested 
against hence the need for the loop

 

Regards

 

Claude Raiola

 

-- 
You received this message because you are subscribed to the Google Groups 
"cfaussie" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cfaussie+unsubscr...@googlegroups.com.
To post to this group, send email to cfaussie@googlegroups.com.
Visit this group at http://groups.google.com/group/cfaussie.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"cfaussie" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cfaussie+unsubscr...@googlegroups.com.
To post to this group, send email to cfaussie@googlegroups.com.
Visit this group at http://groups.google.com/group/cfaussie.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"cfaussie" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cfaussie+unsubscr...@googlegroups.com.
To post to this group, send email to cfaussie@googlegroups.com.
Visit this group at http://groups.google.com/group/cfaussie.
For more options, visit https://groups.google.com/d/optout.

Reply via email to