Solved

arrayDeleteAt - usage?

Posted on 2003-11-12
14
302 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
  • 6
  • 5
  • 3
14 Comments
 
LVL 9

Expert Comment

by:CFDevHead
Comment Utility
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
Comment Utility

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
Comment Utility
Are you passing a form field named submit and if so is it the element on the page passing?
0
 
LVL 6

Expert Comment

by:PE_CF_DEV
Comment Utility
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
Comment Utility
I am sorry I just assumed there were cfoutput tags
0
 
LVL 25

Author Comment

by:James Rodgers
Comment Utility
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
Comment Utility
>>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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 9

Accepted Solution

by:
CFDevHead earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
<cfset arrayDeleteAt(arrFields, arrayLen(arrFields))>


thats what i was looking for !!

0
 
LVL 6

Expert Comment

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

Expert Comment

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

Author Comment

by:James Rodgers
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now