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

count if a letter that you find in all months of the year counts

Participant ,
Oct 05, 2024 Oct 05, 2024

Copy link to clipboard

Copied

Help! I have to count (A) how many times it occurs in the months (therefore in all the days of the year)
I add a code:
var total = 0;
for (var i=1; i<=12; i++) {
for (var j=1; j<=31; j++) {
var f = this.getField("Day"+i+"_"+j);
if (f.valueAsString =="A") total++;

}
}
event.value = total;

TOPICS
PDF , PDF forms

Views

297

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 2 Correct answers

Community Expert , Oct 05, 2024 Oct 05, 2024

Change this:

for (var i=1; i<=12; i++)

To:

for (var i=1; i<=6; i++)

Votes

Translate

Translate
Community Expert , Oct 05, 2024 Oct 05, 2024

Change this:

if (f.valueAsString =="A") total++;

To:

if (f.valueAsString =="A") {
	total++;
	f.textColor = color.red;
} else f.textColor = color.black;

Votes

Translate

Translate
Community Expert ,
Oct 05, 2024 Oct 05, 2024

Copy link to clipboard

Copied

Since there aren't 31 days in each month, you should probably include code that skips missing fields (unless you have created those fields and they are always empty). Beside that, the code seems fine. What happens when you use it?

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
Participant ,
Oct 05, 2024 Oct 05, 2024

Copy link to clipboard

Copied

the months ending on the 30th are left blank.. the problem is that

for (var i=1; i<=12; i++)

doesn't count for me, by checking month by month it reaches July and then it no longer counts as never? Thank you

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 ,
Oct 05, 2024 Oct 05, 2024

Copy link to clipboard

Copied

Check the JS Console for error messages.

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
Participant ,
Oct 05, 2024 Oct 05, 2024

Copy link to clipboard

Copied

If I want, the counting of A ends on June 30th, what can 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 ,
Oct 05, 2024 Oct 05, 2024

Copy link to clipboard

Copied

Change this:

for (var i=1; i<=12; i++)

To:

for (var i=1; i<=6; i++)

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
Participant ,
Oct 05, 2024 Oct 05, 2024

Copy link to clipboard

Copied

Thank you

 

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
Participant ,
Oct 05, 2024 Oct 05, 2024

Copy link to clipboard

Copied

If I want to color text A in red, what can 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 ,
Oct 05, 2024 Oct 05, 2024

Copy link to clipboard

Copied

Change this:

if (f.valueAsString =="A") total++;

To:

if (f.valueAsString =="A") {
	total++;
	f.textColor = color.red;
} else f.textColor = color.black;

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
Participant ,
Oct 06, 2024 Oct 06, 2024

Copy link to clipboard

Copied

LATEST

Thank you

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