googlyralph
asked on
Handling Null Array Locations in a Loop
Hi,
I am writing an online reservation system. I have catagorys of rooms, then individual blocks of rooms in them. To show preferance, to sea front over other catered rooms, you would select a number for the catagory of room, then for the blocks assing a perferance (all down with drop down lists).
im creating a 2D array from this data, then running through it to write out a list of prefered accomodation.
The drop down lists have values that i use as the array index, but as not all catagorys and blocks need a preferance assinged i need a way of skiping over null values.
Is there a simple if(array[x][y].isNull) method? Any other ideas?
Thanks, GR.
I am writing an online reservation system. I have catagorys of rooms, then individual blocks of rooms in them. To show preferance, to sea front over other catered rooms, you would select a number for the catagory of room, then for the blocks assing a perferance (all down with drop down lists).
im creating a 2D array from this data, then running through it to write out a list of prefered accomodation.
The drop down lists have values that i use as the array index, but as not all catagorys and blocks need a preferance assinged i need a way of skiping over null values.
Is there a simple if(array[x][y].isNull) method? Any other ideas?
Thanks, GR.
ASKER
Nope, that doesn work, still get an error. The code im using to "squash" the array out is:
temp = ArrayNew(1);
for(x = ArrayLen(accomOrder); x gt 1; x = x - 1){
temp = accomOrder[x];
if(len(trim(temp[1])) eq 0){
ArrayDeleteAt(accomOrder, x);
continue;
}
for(y = ArrayLen(temp); y gt 1; y = y - 1){
if(len(temp[y]) lt 1){
ArrayDeleteAt(accomOrder[x ], y);
}
}
}
What (i think) its doing:
geting a copy of a 1d array representing a single row in the "table" im making, if the first value is null, then delete the row and run the loop again.
if it gets to a row where the first location is not null, then move along it from right to left, deleting locations in the original 2d array that are null.
Anyone see anything wrong with this code? Any more sugestions?
Cheers, GR.
temp = ArrayNew(1);
for(x = ArrayLen(accomOrder); x gt 1; x = x - 1){
temp = accomOrder[x];
if(len(trim(temp[1])) eq 0){
ArrayDeleteAt(accomOrder, x);
continue;
}
for(y = ArrayLen(temp); y gt 1; y = y - 1){
if(len(temp[y]) lt 1){
ArrayDeleteAt(accomOrder[x
}
}
}
What (i think) its doing:
geting a copy of a 1d array representing a single row in the "table" im making, if the first value is null, then delete the row and run the loop again.
if it gets to a row where the first location is not null, then move along it from right to left, deleting locations in the original 2d array that are null.
Anyone see anything wrong with this code? Any more sugestions?
Cheers, GR.
ASKER
This is the error:
The element at position 1 in dimension 1 of object "temp" cannot be found. That dimension of the object is empty. Please, modify the index expression.
The error occurred while processing an element with a general identifier of (CFSCRIPT), occupying document position (1:1) to (1:10) in the template file e:\tempwebroot\current\tes t\hallsele ctconfirm\ execute.cf m.
The element at position 1 in dimension 1 of object "temp" cannot be found. That dimension of the object is empty. Please, modify the index expression.
The error occurred while processing an element with a general identifier of (CFSCRIPT), occupying document position (1:1) to (1:10) in the template file e:\tempwebroot\current\tes
Have you tried it without using a temp array?
for(x = ArrayLen(accomOrder); x gt 1; x = x - 1){
if(len(trim(accomOrder[x]) ) eq 0){
ArrayDeleteAt(accomOrder, x);
continue;
}
for(y = ArrayLen(accomOrder[x]); y gt 1; y = y - 1){
if(len(accomOrder[x][y]) lt 1){
ArrayDeleteAt(accomOrder[x ], y);
}
}
}
for(x = ArrayLen(accomOrder); x gt 1; x = x - 1){
if(len(trim(accomOrder[x])
ArrayDeleteAt(accomOrder, x);
continue;
}
for(y = ArrayLen(accomOrder[x]); y gt 1; y = y - 1){
if(len(accomOrder[x][y]) lt 1){
ArrayDeleteAt(accomOrder[x
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just a question, could you Output the content of your Array with CF_OBJECTDUMP ? If yes, i think that cheekycj's solution should work... if not, maybe some part of your Array are not defined at all !! Then you have to resolve your problem when you create the Array, not when the Array is created !
Could you display the content of your Array ?
Cyril
Could you display the content of your Array ?
Cyril
ASKER
I have found an alternative to using htis template now, so i am not overly concerned why this doesnt work. I will assign the points to Cheekyci for the time and effort.
Thanks, GR.
Thanks, GR.
thanx for the pts. Glad you got it working, would you care to post your solution for future reference?
Thanx,
CJ
Thanx,
CJ
ASKER
Not really relevent, took an alternative route, and used client side validation instead.
Thanks for your help.
GR.
Thanks for your help.
GR.
<cfif LEN(TRIM(myArrayVariable[x
<!--- handle null --->
<cfelse>
<!--- handle not null --->
</cfif>
Assuming your data is strings.
CF has the nice capability of being typeless so everthing can be seen as a string.
CJ