Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array problems 2

Status
Not open for further replies.

iao

Programmer
Feb 23, 2001
111
US
I am trying to build a program which displays a list of supervisor's employee's. Each employee has three fields: current status, total hours, and total amount($).

I have a query called QempList which selects the employee for each supervior selected. So, if I had two employees under me, the QempList query would return 2 records.

I have built the following code to run each time a supervisor accesses this portion of the form:

<CFSET TDArr = ArrayNew(1)>
<CFLOOP FROM=&quot;1&quot; TO=&quot;#qEmpList.RecordCount#&quot; INDEX=i>
<CFSET TDArr = StructNew()>
<!--- Get Status --->
<CFSET TDArr.STATUS = qStat.STATUS>
<CFSET TDArr.TOTALHOURS = qPerTotals.TOTALHOURS>
<CFSET TDArr.TOTALAMOUNT = qPerTotals.TOTALAMOUNT>
</CFLOOP>

The problem I have is that every time this is run I get an error if one of the fields are empty. For example, if there are currently no hours, I get an error which says &quot;The element at position 2 in dimension 1 of object &quot;qPerTotals.TOTALHOURS&quot; cannot be found. That dimension of the object is empty. Please, modify the index expression.&quot;

I tried an IsDefined and that didn't solve the problem. Any tips on how to resolve this problem?
 
Hey Eco,

I may not understand your problem entirely but I think this might help:

<cfif isnumeric( qPerTotals.TOTALHOURS)>
<CFSET TDArr.TOTALHOURS = qPerTotals.TOTALHOURS>
<cfelse>
<CFSET TDArr.TOTALHOURS = 0>
</cfif>

It sounds like you just need to set the array to zero in the even the field is null. Let me know if this doesn't work. Also, I'm assuming this is some type of typo but your query name &quot;qPerTotals&quot; doesn't match the name specified in your <cfloop> tag.

Hope this helps,
GJ
 
There are a couple of ways to go about this.

One you have allready tried (isDefined, or parameterexists )
which should work if done correctly.

The other way that you may want to try is making sure that there is something in that field. When you put the data in you can check that if there is no other value it enters 0. Or if you have the flexibility of a text field you could put &quot;n/a&quot; or anything to make there be content.

If you need help implementing either of these let us know. We'll see what we can do.
 
Aaah. I see, I will give it a shot.

Thanks for the help!!!
 
Hehe, no problem. Happened to me earlier today with someone else.

GJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top