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

# NESTED IF/THEN STATEMENT

Community Beginner ,
Jul 04, 2023 Jul 04, 2023

Copied

Is it possible to create an if/then statement where if B4 =  B3+1 than display the first number and the last number with a dash in between and if not then put a dash after the number in the cell.  Result I am looking for based on the below would be: 64, 114-118, 282-284, 288-290. Any help is greatly appreciated.

Example:

Cell B3 is 64, Cell B4 is 114 and so on.

 MAP 64 114 115 116 117 118 282 283 284 288 289 290
TOPICS
Acrobat SDK and JavaScript

Views

247

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
2 Replies 2
Community Beginner ,
Jul 04, 2023 Jul 04, 2023

Copied

Is it possible to create an if/then statement where if B4 =  B3+1 than display the first number and the last number in the sequence with a dash in between and if not then put a comma after the number in B3.  Result I am looking for based on the below would be: 64, 114-118, 282-284, 288-290. Any help is greatly appreciated.

Example:

Cell B3 is 64, Cell B4 is 114 and so on.

 MAP 64 114 115 116 117 118 282 283 284 288 289 290

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 Expert ,
Jul 04, 2023 Jul 04, 2023

Copied

LATEST

The answer is that you can create a script that arranges a list of numbers into a list of ranges.  Not exactly an "if" statement, but there will be "if"s 😉

Here's an example:

``````var aNums = [1,2,3,14,16,17,20];
var aCollect = [];
aNums.forEach(function(a,i,lst){
// If first or non-consecutive number, then push onto collection
if(!i || (lst[i-1]!= (a-1))) aCollect .push([a]);
// If consecutive number,  push onto (keep with)last element in collection
else aCollect [aCollect .length-1].push(a);
})
// convert to range.
var aRanges = aCollect .map(function(a){return (a.length == 1)?a[0]:a[0] + "-" + a.pop();})

``````

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often