Your code is incomplete, so I can't see exactly what you are doing
(struct definitions are missing). But this code will not work because
you have the order of keys in the struct requestLimit inverted in the
second part (see inline). Thes cfif is not necessary as it will always
return false (as I see it). Also, I hope you have the keys in the
requestLimit defined as arrays. From what I see here, you should have
some code like:

<cfset requestLimit = StructNew()>
<cfset requestLimit.Date = ArrayNew(1)>
<cfset requestLimit.Threshold = ArrayNew(1)>
<cfset requestLimit.RequestCount = ArrayNew(1)>
<cfset requestLimit.Blackout = ArrayNew(1)>

This should make your code work, but I am not sure this will do what you
want. But I can't say that if I don't have more info.

If I should take a guess, I would say you are having some info over a
specific month. You have some days (with info) in the db and you want
all days of that month with that info (empty if it is not in the db). If
my guess is right, here is how I would do it. I am assuming that all the
days in your query are from the same month.

<cfset requestLimit = ArrayNew(1)>
<cfset emptyStruct = StructNew()>
<cfset emptyStruct.treshhold = 0>
<cfset emptyStruct.requestCount = 0>
<cfset emptyStruct.blackout = 0>
<cfset days = DaysInMonth(CreateDate(year, month,  1))>
<cfloop index="i" from="1" to="#days#">
<cfset requestLimit[i] = Duplicate(emptyStruct)>
<cfset requestLimit[i].date = DateFormat(CreateDate(year, month,
i), "mm/dd/yyyy")>
</cfloop>
<cfloop query="getFlexDays">
<cfset i = Day(getFlexDays.flexRequestDateRequested)>
<cfset requestLimit[i].treshhold = getFlexDays.treshhold>
<cfset requestLimit[i].requestCount = getFlexDays.requestCount>
<cfset requestLimit[i].blackout = getFlexDays.blackout>
</cfloop>
<cfdump var="#requestLimit#">

Pascal Peters
Certified ColdFusion MX Advanced Developer
Macromedia Certified Instructor
LR Technologies
Av. E. De Mot, 19
1000 BRUSSELS, BELGIUM
Tel: +32 2 639 68 70
Fax: +32 2 639 68 99
Email: [EMAIL PROTECTED]
Web: www.lrt.be

> -----Original Message-----
> From: Levenson, Keith [mailto:[EMAIL PROTECTED]
> Sent: donderdag 18 maart 2004 18:26
> To: CF-Talk
> Subject: Adding elements to a structure
>
> I'm new to using structures, and am having difficultly adding
> elements to an existing structure.
>
> Here's the code snippet:
>
>
> <cfoutput query="getFlexDays">
> <cfset requestLimit.Date[currentrow] =
> DateFormat(getFlexDays.flexRequestDateRequested, "mm/dd/yyyy")>
> <cfset requestLimit.Threshold[currentrow] =
> getFlexDays.flexDayThresholdMax>
> <cfset requestLimit.RequestCount[currentrow] =
> getFlexDays.flexRequestCount>
> <cfset requestLimit.Blackout[currentrow] =
> getFlexDays.flexDayBlackout> </cfoutput>
>
> <cfset counter = StructCount(requestLimit)>

This should be counter = getFlexDays.recordCount
>
> <cfloop from="1" to="#Days#" index="x">
> <cfset counter = incrementValue(counter)>
> <cfset dateTest = DateFormat(CreateDate(Year, Month,
> x), "mm/dd/yyyy")>
> <cfif structkeyexists(requestLimit, #dateTest#)>
> <cfelse>
> <cfset
> StructInsert(requestLimit[counter], "Date",
> #DateFormat(CreateDate(Year, Month, x), "mm/dd/yyyy")#)>
> <cfset StructInsert(requestLimit[counter],
> "Threshold", 0)>
> <cfset StructInsert(requestLimit[counter],
> "RequestCount", 0)>
> <cfset StructInsert(requestLimit[counter],
> "Blackout", 0)>

This should be

<cfset requestLimit.Date[counter] = dateTest>
<cfset requestLimit.Threshold[counter] = 0>
<cfset requestLimit.RequestCount[counter] = 0>
<cfset requestLimit.Blackout[counter] = 0>

> </cfif>
> </cfloop>
>
>
> There are 4 elements in the structure from the population in
> the output query.  When the fifth is added in the loop, I get
> this error message:
>
> Element 5 is undefined in a CFML structure referenced as part
> of an _expression_.
> Any pointers would be appreciated.  Thanks!
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to