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

Dialog EditText field collect array?

Engaged ,
Dec 20, 2020 Dec 20, 2020

Copy link to clipboard

Copied

I want to have a field in my dialog box that will collect and array of numbers seperated by comma. Would I need to collect that as a string or can i go strait to an array? If not how would I convert that string?

 

var dialog = new Window("dialog"); 
    dialog.text = "SETUP"; 
    dialog.orientation = "row"; 
    dialog.alignChildren = ["left","top"]; 
    dialog.spacing = 10; 
    dialog.margins = 16; 

// GROUP1
// ======
var group1 = dialog.add("group", undefined, {name: "group1"}); 
    group1.preferredSize.width = 343; 
    group1.orientation = "column"; 
    group1.alignChildren = ["left","center"]; 
    group1.spacing = 9; 
    group1.margins = 0;

var edittext1 = group1.add('edittext {properties: {name: "edittext1"}}'); 
    edittext1.text = "Page numbers ie. 1,5,9"; 
    edittext1.preferredSize.width = 368; 
    edittext1.preferredSize.height = 30; 

var result = dialog.show();
----------
var pagesVar = (edittext1.text);
var pageNumbers = pagesVar.match(/\d+/g); //Tried this doesn't seem to work

$.writeln(edittext1.text);
$.writeln(pageNumbers.length-1);//tested to see if I could get the last number, didn't give the correct one

 

TOPICS
Scripting

Views

354

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 1 Correct answer

Engaged , Dec 20, 2020 Dec 20, 2020

I got it. 

 

var pagesVar = (edittext1.text);
var pageNumbers = eval('['+pagesVar+']');

Votes

Translate

Translate
Engaged ,
Dec 20, 2020 Dec 20, 2020

Copy link to clipboard

Copied

I got it. 

 

var pagesVar = (edittext1.text);
var pageNumbers = eval('['+pagesVar+']');

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 ,
Dec 20, 2020 Dec 20, 2020

Copy link to clipboard

Copied

Alternatively, assuming comma-separated entries in the text field: 

var pageNumbers = edittext1.text.split(",");

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
Engaged ,
Dec 21, 2020 Dec 21, 2020

Copy link to clipboard

Copied

I tried this but couldn't get it to work, I had just assumed it wasn't available in extendscript.

 

 

var lastPage = pageNumbers[pageNumbers.length-1];
myDoc.documentPreferences.pagesPerDocument = lastPage;

 

 

The error I get is Expected Long Integer, but received "16". I'm assuming by the quotes that it is still a string. 

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 ,
Dec 21, 2020 Dec 21, 2020

Copy link to clipboard

Copied

LATEST

Correct. You can use parseInt to convert it: 

myDoc.documentPreferences.pagesPerDocument = parseInt(lastPage);

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