Solved

arrayDeleteAt - usage?

Posted on 2003-11-12
14
309 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
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

820 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