Syntax Error

I'll pose this question here rather than sending a support request, because it may affect some other people sometime too.

Will the program process a Java Script if-Statement? If so, is a special syntax necessary? As far as I can see, the following if-Statement should be valid:

if (chkAnimalCompanion.Value == TRUE) {
'd20+'+(txtKnoMod.Value+txtAnimalCompanionSP.Value);
}

However, it throws a compilation error.

chkAnimalCompanion is a check box.
txtKnoMod and txtAnimalCompanionSP are text edit fields.

CS Designer seems to want apostrophes (single quotes) rather than real (double) quotes, but the statement above works with neither. The error also appears with a single = sign rather than a double (==).

Comments

  • If you are placing this in the field source, no, I dont think this will work because the field source needs to be an expression that returns a value.

    You could though make a function on the script page, and call that from the field source.
  • It may just be a syntax problem on my part. I'm a C++ programmer, not a Java Script programmer. I tried to guess the proper JS syntax from your examples, but that doesn't seem to work either. I wrote the following function (The forum editor ignores my indents.):

    function Prerequisite (TrueFalse, KnoMod, SP)
    {
    r = 0;

    if (TrueFalse == TRUE)
    {
    r = KnoMod + SP;
    }
    return r;
    }

    ... and I called it as follows:

    Prerequisite (chkAnimalCompanion.Value, txtKnoMod.Value, txtAnimalCompanionSP.Value)

    ... in the Field Source box. However, the only result is to call the debugger.

    It could also be that I'm doing more than CS Designer's up to.
  • I've attached an example that has that function for a field source. Javascript can be picky if you're used to other languages.

    One problem is the "TrueFalse == TRUE", which in JS, you'd just say "if (TrueFalse)" or "if (TrueFalse == true)", since 'true' in javascript is an actual identifier, as opposed to C++ where TRUE is a defined value.
  • Great. Works fine.

    if (TrueFalse)

    works in C++ too, if the value of TrueFalse is right.

    I assumed that VS also had the symbolic constant TRUE. Bad guess.

    I also wasn't aware of the Checked property for a check box, as in:

    chkAnimalCompanion.Checked

    Once I get this thing done, I'll make it available, so that other users can see how to do a couple of things that aren't in the original samples.

    Thanx,

Leave a Comment