|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
hi,
let's say i have the following array. A[1] = 104 A[2] = 204 A[3] = 304 .... A[123] = 1126 A[124] = 1127 There is a form where user inputs the value for A[X] and A[Y] how can i compare these two values to my array and get anything in between? I tried converting them into list to use ListGetAt but for some reason i couldn't get it work. Java is throwing out of bonds error... thanks for the help in advance |
|
#2
|
||||
|
||||
|
If the user is inputting x and y in another page via a form, then it would be:
<cfset firstval=A[Form.x]> <cfset secondval=A[Form.y]> This will work fine as long as you can ensure that they don't put in 0 or something out of the array bound. I don't know what you mean by "get anything in between", but you could figure out the numerical difference by just using the form variables, or you could return all the indices of the array between the two values by doing a loop using the form variables. But again, I don't know what you're trying to do exactly. Hope that helps though. |
|
#3
|
|||
|
|||
|
Quote:
thanks bocmaxima, i am trying to get the values that i hold in the array. suppose the user enters 204 and 1126. then i will need to get all those values starting with 304. i tried doing a loop but for some reason it doesnt work. <cfset yP1 = #FORM.one#> <!--- first search value ---> <cfset yP2 = #FORM.two#><!--- second search value---> <cfset ATL = ArrayToList(MonYear)> <!---converted to list---> <cfset firstPos = #ListFind(#ATL#, #yP1#)#><cfoutput>first pos : #firstPos#</cfoutput> <cfset secondPos = #ListFind(#ATL#, #yP2#)#><cfoutput>second pos : #secondPos#</cfoutput> <cfif firstPos GT secondPos> <cfloop index="jj" from="#firstPos#" to="#secondPos#" step="1"> <cfset crap= #ListGetAt(#ATL#,#jj#)#> <cfoutput>#crap#</cfoutput> </cfloop> </cfif> <cfif firstPos LT secondPos> <cfloop index="jj" from="#secondPos#" to="#firstPos#" step="1"> <cfset crap= #ListGetAt(#ATL#,#jj#)#> <cfoutput>#crap#</cfoutput> </cfloop> </cfif> |
|
#4
|
|||
|
|||
|
nevermind
, i figured it out... |
|
#5
|
|||
|
|||
|
Just an observation. I'm not sure what you're trying to do, but this seems like a very inefficient method. Whenever you see code that is that complicated a red flag should probably be going off in your head.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#6
|
|||
|
|||
|
perhaps this will make it easier to understand
form.field1 = 104 (Jan 04) form.field2 = 305 (mar 05) so i need to find out how many months are in between and represent them in the same format ... the months are 104,204,304,404,504,604,704,804,904,1004,1104,1204,105,205,305 these value will go to a query as in select ... from... where billcycle in (104,204,304,404,504,604,704,804,904,1004,1104,1204,105,205,305) so, i decided to create an array. populate the array with these values (right now from 100(jan 00) to 1299(dec 2099) then extract the values that satisfies the users search criteria. then search the invoices with those billing cycles. it might not be the most efficient method. if anyone knows a better way to do it, please let me know... |
|
#7
|
|||
|
|||
|
hmm...yes the fact that you aren't storing the month and year as a valid date is the big stumbling block. If you could store that as a valid date this would be much easier to do. This solution isn't that much more simple, but it avoids all list conversions and the multiple loops.
Code:
<cfset time1 = "104" /> <cfset time2 = "305" /> <!--- Add leading 0 if needed. ---> <cfif len( trim( time1 ) ) eq 3> <cfset time1 = 0 & trim( time1 ) /> </cfif> <cfif len( trim( time2 ) ) eq 3> <cfset time2 = 0 & trim( time2 ) /> </cfif> <cfset date1 = createDate( 20 & right( time1, 2 ), left( time1, 2), 1 ) /> <cfset date2 = createDate( 20 & right( time2, 2 ), left( time2, 2), 1 ) /> <!--- Build a result array. ---> <cfset resultArray = arrayNew(1) /> <cfset resultArray[1] = "#month( date1 )##dateFormat( date1, 'yy' )#" /> <cfloop index="thisMonth" from="1" to="#dateDiff( 'm', date1, date2 )#"> <cfset newDate = dateAdd( 'm', thisMonth, date1 )> <cfset arrayAppend( resultArray, '#month( newDate )##dateFormat( newDate, 'yy' )#' ) /> </cfloop> <cfdump var="#arrayToList( resultArray )#"> Last edited by kiteless : September 15th, 2004 at 10:06 AM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Array question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|