Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

arrayDeleteAt - usage?

Posted on 2003-11-12
14
Medium Priority
?
319 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
Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

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…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

636 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