Solved

arrayDeleteAt - usage?

Posted on 2003-11-12
14
315 Views
Last Modified: 2013-12-24
this works- deletes the last element of the array
<cfif isDefined("form.fieldNames")>
<cfset arrFields=listToArray(form.fieldNames)>
<cfif ucase(arrFields[arrayLen(arrFields)]) eq ucase("submit")>
      <cfif #arrayDeleteAt(arrFields, arrayLen(arrFields))#>
      
      </cfif>
</cfif>
</cfif>
this also works, but outputs a YES to the screen

<cfif isDefined("form.fieldNames")>
<cfset arrFields=listToArray(form.fieldNames)>
<cfif ucase(arrFields[arrayLen(arrFields)]) eq ucase("submit")>
      <cfoutput> #arrayDeleteAt(arrFields, arrayLen(arrFields))#
      
      </cfoutput>
</cfif>
</cfif>

but this doesn't

<cfif isDefined("form.fieldNames")>
<cfset arrFields=listToArray(form.fieldNames)>
<cfif ucase(arrFields[arrayLen(arrFields)]) eq ucase("submit")>
       #arrayDeleteAt(arrFields, arrayLen(arrFields))#
</cfif>
</cfif>

what is the proper method for using this function?
0
Comment
Question by:James Rodgers
[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
  • 6
  • 5
  • 3
14 Comments
 
LVL 9

Expert Comment

by:CFDevHead
ID: 9734762
I am not sure what is not working the last function seems to work just fine as long your submit button is named submit and the last form element in the array.
0
 
LVL 25

Author Comment

by:James Rodgers
ID: 9734877

when i run the last block of code i get this output to the page

#arrayDeleteAt(arrFields, arrayLen(arrFields))#

and it doesn't execute the command

0
 
LVL 9

Expert Comment

by:CFDevHead
ID: 9734897
Are you passing a form field named submit and if so is it the element on the page passing?
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 6

Expert Comment

by:PE_CF_DEV
ID: 9734965
when i run the last block of code i get this output to the page

#arrayDeleteAt(arrFields, arrayLen(arrFields))#

and it doesn't execute the command
----------------------------------------------------
thats because you have no <cfoutput> tags around it :-))

Without cfoutput tags around it coldfusion will not proccess it and assumes its just text to be output
0
 
LVL 9

Expert Comment

by:CFDevHead
ID: 9734999
I am sorry I just assumed there were cfoutput tags
0
 
LVL 25

Author Comment

by:James Rodgers
ID: 9735011
in the first two code blocks the form field submit is deleted from the array but in the third one nothing is happening and it makes no sense, at least to me, as to why the function does not perform when called as

#arrayDeleteAt(arrFields, arrayLen(arrFields))#
but if included in a cfoutput block it works and outputs 'YES' or if included in an empty CFIF it works with no output

i have the page doing what i want,
i'm just trying to understand why i have to do it with the empty CFIF to get it to work!
0
 
LVL 25

Author Comment

by:James Rodgers
ID: 9735054
>>Without cfoutput tags around it coldfusion will not proccess it and assumes its just text to be output

but i don't want the 'YES' outpout -- i just wanted the array element deleted, and i dont want to perform an action if the delete was successful or not so why the need ---

the arrayDeleteAt seems as tho it would be better as a tag
0
 
LVL 9

Accepted Solution

by:
CFDevHead earned 500 total points
ID: 9735062
Ok arrayDeleteAt is boolean function it retruns a yes or no this why it outputs a yes.

you don't have to run this function in an empty cfif but you do have to run it either between cfoutput tags or call it from a cf tag example
<cfset arrayDeleteAt(arrFields, arrayLen(arrFields))>

if you don't do this cf thinks it is just text.
0
 
LVL 6

Expert Comment

by:PE_CF_DEV
ID: 9735084
Like I said if you do not have cfoutput tags around the thing coldfusion will not proccess it.

When it is in the <cfif> tag coldfusion proccess the <cfif> tag which means it will proccess the arraydelete command.

in your final version:
<cfif isDefined("form.fieldNames")>
<cfset arrFields=listToArray(form.fieldNames)>
<cfif ucase(arrFields[arrayLen(arrFields)]) eq ucase("submit")>
      #arrayDeleteAt(arrFields, arrayLen(arrFields))#
</cfif>
</cfif>

nothing is telling coldfusion to proccess the #arrayDeleteAt(arrFields, arrayLen(arrFields))#.

The best way to prove this is try this:
<body bgcolor=#00000>

then try this:
<cfoutput>
<body bgcolor=#00000>
</cfoutput>

Coldfusion will throw an error becuase couldfusion was told to look for # signs since you put a <cfoutput> tag in there. the proper way would be:
<cfoutput>
<body bgcolor=##00000> <!--- this effectively ecspaces the # sign --->
</cfoutput>

0
 
LVL 9

Expert Comment

by:CFDevHead
ID: 9735087
You should read the macromedia coldfusion language refernce it would help alot.

Description
Deletes an element from an array.

When an element is deleted, ColdFusion recalculates index positions. For example, in an array that contains the months of the year, deleting the element at position 5 removes the entry for May. After this, to delete the entry for June, you would delete the element at position 5 (not 6).

Returns
True, on successful completion.

Category
Array functions

Function syntax
ArrayDeleteAt(array, position)

See also
ArrayInsertAt

History
ColdFusion MX:

Changed behavior: this function can be used on XML objects.
Changed thrown exceptions: this function can throw the InvalidArrayIndexException error.
Parameters
 Parameter Description
array
 Name of an array
 
position
 Array position
 


Throws
If this function attempts to delete an element at position 0, or specifies a value for position that is greater than the size of array, this function throws an InvalidArrayIndexException error.

Example
<h3>ArrayDeleteAt Example</h3><p>
<!--- create an array --->
<cfset DaysArray = ArrayNew(1)>
<!--- populate an element or two --->
<cfset DaysArray[1] = "Monday">
<cfset DaysArray[2] = "Tuesday">
<cfset DaysArray[3] = "Wednesday">
<!--- delete the second element --->
<p>Is the second element gone?:
 <cfoutput>#ArrayDeleteAt(DaysArray,2)#</cfoutput>
<!--- the formerly third element, "Wednesday" is second element --->
<p>The second element is now: <cfoutput>#DaysArray[2]#</cfoutput>

0
 
LVL 25

Author Comment

by:James Rodgers
ID: 9735145
<cfset arrayDeleteAt(arrFields, arrayLen(arrFields))>


thats what i was looking for !!

0
 
LVL 6

Expert Comment

by:PE_CF_DEV
ID: 9735168
<cfset temp = #arrayDeleteAt(arrFields, arrayLen(arrFields))#>
0
 
LVL 9

Expert Comment

by:CFDevHead
ID: 9735183
There is no reason to set it in to temp variable.
0
 
LVL 25

Author Comment

by:James Rodgers
ID: 9735227
sorry,

accepted answer should have been

Comment from CFDevHead
Date: 11/12/2003 04:55PM EST
 Comment  

Ok arrayDeleteAt is boolean function it retruns a yes or no this why it outputs a yes.

you don't have to run this function in an empty cfif but you do have to run it either between cfoutput tags or call it from a cf tag example
<cfset arrayDeleteAt(arrFields, arrayLen(arrFields))>

if you don't do this cf thinks it is just text.
 
i will ask cs to adjust
0

Featured Post

Save the day with this special offer from ATEN!

Save 30% on the CV211 using promo code EXPERTS30 now through April 30th. 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

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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