• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Syntax Error in Formula

Explorer ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

Guys,

 

I'm trying to do a conditional formula where it compares two fields, and only calculates if one field is greater than the other. Here is the code I've cobbled together from multiple other codes that did what I wanted -in part-.

 

Can you guys tell me where I'm going wrong?

 

var 12 = this.getField("Line 12").value;
var 13 = this.getField("Line 13g").value;
if( 12 > 13) event.value = this.getField("Line 12").value - this.getField("Line 13g").value;
else event.value = "0"

TOPICS
JavaScript

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 4 Correct answers

Community Expert , Apr 23, 2021 Apr 23, 2021

Don't use numbers as name of variables.

Votes

Translate

Translate
Community Expert , Apr 23, 2021 Apr 23, 2021

Variable name can't start with a number.

Votes

Translate

Translate
Community Expert , Apr 23, 2021 Apr 23, 2021

In your screenshot, notice the message "illegal character 2: at line 3".

 

Look at the quotes used in the line of code for "var B".

 

It seems like you copied the code from another program ( or an open webpage in your web browser) and then pasted it directly into the JavaScript editor.

Make sure you're using the same quote typeface as you have in the rest of your script.

 

Also, to be on the safe side, you may want to close  the last line for event.value = "0" with a semicolon ";".

Votes

Translate

Translate
Community Expert , Apr 23, 2021 Apr 23, 2021

Now your missing a quote in this line "Line 13g 

 

Since you declared variables already your script can be typed in much shorter like:

 

if (A > B) event.value = A-B;

 

Votes

Translate

Translate
Community Expert ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

Don't use numbers as name of variables.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

CHaynes8185_0-1619204792055.png

New error, now.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

Variable name can't start with a number.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

Thanks to you, too!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

CHaynes8185_0-1619204818351.png

New error.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

CHaynes8185_0-1619204491078.png

New error. Any help appreciated!

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

In your screenshot, notice the message "illegal character 2: at line 3".

 

Look at the quotes used in the line of code for "var B".

 

It seems like you copied the code from another program ( or an open webpage in your web browser) and then pasted it directly into the JavaScript editor.

Make sure you're using the same quote typeface as you have in the rest of your script.

 

Also, to be on the safe side, you may want to close  the last line for event.value = "0" with a semicolon ";".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

Thank you! That's 100% what I did. Now I'm getting this:

CHaynes8185_0-1619205779070.png

I'm on the last line! I'm sorry to keep posting about it, but I don't do JavaScript often, and I like to mess it up good when I do!

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

Why have you removed " after 13g?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

Accident because I retyped the whole this to make sure the font matched and forgot the "

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

Now your missing a quote in this line "Line 13g 

 

Since you declared variables already your script can be typed in much shorter like:

 

if (A > B) event.value = A-B;

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

PERFECT! Changed that line and it's working now.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2021 Apr 23, 2021

Copy link to clipboard

Copied

LATEST

THANKS EVERYBODY! Combination of correct answers to help me limp along! Got it worked out!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines