?
Solved

arrayDeleteAt - usage?

Posted on 2003-11-12
14
Medium Priority
?
317 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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 2000 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

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

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…
What You Need to Know when Searching for a Webhost Provider
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

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