Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6698333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:33:56+00:00 2026-05-26T06:33:56+00:00

I am finally getting around to writing stuff in cfscript, and so I am

  • 0

I am finally getting around to writing stuff in cfscript, and so I am starting with writing some needed formatting functions. Here is an example:

    Function FormatBoolean(MyBool, Format) { 

    Switch(Format){
        Case "YES/NO":{
            If (MyBool eq 1)
                Return "YES";
            Else
                Return "NO";
            Break;
        }

        Default:{
            If (MyBool eq 1)
                Return "Yes";
            Else
                Return "";
            Break;
        }
    }
}

What I would like to do is make Format an optional argument. If you don’t include the argument, the function will currently still run, but it won’t find format, and it seems that cfparam did not get translated to cfscript.

Will I just have to check if Format is defined and give it a value? Or is there a nicer way of doing this?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:33:56+00:00Added an answer on May 26, 2026 at 6:33 am

    Personally I prefer to set defaults to this kind of arguments. Also I’ve refactored function a bit… But not tested 🙂

    function FormatBoolean(required any MyBool, string Format = "") { 
    
        switch(arguments.Format) {
            case "YES/NO":
                return YesNoFormat(arguments.MyBool EQ 1);
            default:
                return (arguments.MyBool eq 1) ? "Yes" : "";
        }
    
    }
    

    Please note that (arguments.MyBool EQ 1) may be replaced with (arguments.MyBool), so it covers all boolean values. You may be interested to make it more reliable, something like this (isValid("boolean", arguments.MyBool) AND arguments.MyBool) — this should allow to check any value at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am finally getting around to really implementing some jQuery solutions for my apps
Recently in our work, I've started getting some experience with SEO (finally). It's something
I have an older 2.x Android app that I am finally getting around to
I'm finally getting around to adding icons to our pull down menus: In this
I'm finally getting around to checking out the latest EF release and I'm running
This has happened to me a million times and I'm finally getting around to
Loooong time viewer, finally getting round to signing up here at StackOverflow! After a
I'm finally getting my team to embrace source code management now that we're working
I've recently moved from VB6 to VB.NET and I am finally getting there with
I'm getting ready to finally deploy my first iPhone app. The app uses SSL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.