ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 17th, 2005, 10:59 PM
hoolahawk hoolahawk is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: Australia
Posts: 57 hoolahawk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 29 m 43 sec
Reputation Power: 5
Needing a return value in a function

Hi,

Does anyone know if you have to return anything using a udf? Can you use it to display a onscreen message for false and do nothing for true or should you always return something?

Regards

Reply With Quote
  #2  
Old April 17th, 2005, 11:26 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,700 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 17 h 45 m 21 sec
Reputation Power: 53
It's perfectly valid for a function to return nothing (also known as returning void). But definitely do one or the other, don't only return a value conditionally...either return a value all the time or don't return a value ever. The value can just be "true", "false", 0, or whatever. Or you can throw an exception if something unexpected happens and let the calling code deal with the exception however it wants to.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old April 17th, 2005, 11:43 PM
hoolahawk hoolahawk is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: Australia
Posts: 57 hoolahawk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 29 m 43 sec
Reputation Power: 5
Hi Kiteless,

I've got a rather long form and I use js validation as well as server-side validation. I wanted a way of re-using validation code rather than having a very long action page that validates all of the form data.

I decided to use a UDF which checks if a form field is required and displays a error message if no data has been entered or moves on to the next function call if data has been added.

I was not sure if you needed to have it return any thing or just call the error message straight from the function.

Reply With Quote
  #4  
Old April 18th, 2005, 08:44 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,700 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 17 h 45 m 21 sec
Reputation Power: 53
It's really just a question of consistency. Whatever you decide to return, then stick with it. So if the function returns a string that holds a Javascript error checking script or an error message, then just have it return an empty string when no error is found (for example).

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Needing a return value in a function


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT