ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old September 14th, 2004, 03:33 PM
FALCONSEYE FALCONSEYE is offline
Permanently Banned
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 377 FALCONSEYE Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 1 Day 16 h 57 m 14 sec
Warnings Level: 15
Number of bans: 1
Reputation Power: 0
Question Array question

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

Reply With Quote
  #2  
Old September 14th, 2004, 03:40 PM
bocmaxima's Avatar
bocmaxima bocmaxima is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2004
Location: Tucson, Sonora
Posts: 1,322 bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 17 h 44 m 38 sec
Reputation Power: 22
Send a message via AIM to bocmaxima
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.

Reply With Quote
  #3  
Old September 14th, 2004, 03:51 PM
FALCONSEYE FALCONSEYE is offline
Permanently Banned
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 377 FALCONSEYE Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 1 Day 16 h 57 m 14 sec
Warnings Level: 15
Number of bans: 1
Reputation Power: 0
Quote:
Originally Posted by bocmaxima
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]>


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.


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>

Reply With Quote
  #4  
Old September 14th, 2004, 03:54 PM
FALCONSEYE FALCONSEYE is offline
Permanently Banned
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 377 FALCONSEYE Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 1 Day 16 h 57 m 14 sec
Warnings Level: 15
Number of bans: 1
Reputation Power: 0
nevermind , i figured it out...

Reply With Quote
  #5  
Old September 14th, 2004, 04:26 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,611 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 9 h 10 m 21 sec
Reputation Power: 53
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

Reply With Quote
  #6  
Old September 14th, 2004, 04:40 PM
FALCONSEYE FALCONSEYE is offline
Permanently Banned
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 377 FALCONSEYE Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 1 Day 16 h 57 m 14 sec
Warnings Level: 15
Number of bans: 1
Reputation Power: 0
Cool

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...

Reply With Quote
  #7  
Old September 15th, 2004, 08:45 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,611 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 9 h 10 m 21 sec
Reputation Power: 53
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Array question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway