Solved

Handling Null Array Locations in a Loop

Posted on 2002-03-06
9
152 Views
Last Modified: 2013-12-24
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.
0
Comment
Question by:googlyralph
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 19

Expert Comment

by:cheekycj
ID: 6844581
something like

<cfif LEN(TRIM(myArrayVariable[x][y])) EQ 0>
  <!--- 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
0
 
LVL 1

Author Comment

by:googlyralph
ID: 6846871
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.
0
 
LVL 1

Author Comment

by:googlyralph
ID: 6846876
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\test\hallselectconfirm\execute.cfm.
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 19

Expert Comment

by:cheekycj
ID: 6847822
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);
      }
   }
 }
0
 
LVL 19

Accepted Solution

by:
cheekycj earned 50 total points
ID: 6855163
any luck?
0
 
LVL 2

Expert Comment

by:Cyril_H
ID: 6856065
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
0
 
LVL 1

Author Comment

by:googlyralph
ID: 6941393
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.
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 6942225
thanx for the pts.  Glad you got it working, would you care to post your solution for future reference?

Thanx,
CJ
0
 
LVL 1

Author Comment

by:googlyralph
ID: 6942241
Not really relevent, took an alternative route, and used client side validation instead.

Thanks for your help.

GR.
0

Featured Post

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question