5 Replies Latest reply on Nov 7, 2012 2:19 AM by Jump_Over

# how to set if, else???

for example:

if i want to text convert to table.

If have ";" x 4

col1;col2;col3;col4

(script 1)

col1col2col3col4

else

if have ";" x5

(script 2)

var myTable = app.selection[0].convertToTable(";","\r");

col1;col2;col3;col4;col5

col1col2col3col4col5

and if have ";"x6 =(script 3), ";" x 7 = (script 4), ";" x8  (scr.......

i want only use a script to do, how can i do that??

thankyou>< love your

• ###### 1. Re: how to set if, else???

You don't have to count the number of ;'s. The function convertToTable will never create more columns than needed.

• ###### 2. Re: how to set if, else???

but i want to set colnum wifth.

different colnum number different width...

example: if ";" x3

col1 width = "90 mm" col2 = "30mm" col3 = "30mm"

of ";" x 4

col1 width = "75mm" cold 2 width = "25mm" col 3 width = "25mm" col 4 width = "25mm"

because i have many script 1 for 3 column, script 2 for 4 column.

how can i integrate to one script.

• ###### 3. Re: how to set if, else???

Hi,

Could you find a rule when calculating columns width?

Could it be: 1st column is 3 times wider then the rest?

If your table width is a textFrame width - all the rest is mathematics

and can be done in one loop.

• ###### 4. Re: how to set if, else???

actually i'm not want to set colnum width.....

i need count the character ";".....sorry...

if         1;2;3;4       <----have three ";"

run script 1

if 1;2;3;4;5             <------have four ";"

run script 2

if       1;2;3;4;5;6   <--------have five ";"

run script 3

• ###### 5. Re: how to set if, else???

Hi,

So you could use a switch:

var whichScript = myTable.columns.length;

or

var whichScript = app.selection[0].texts[0].contents.split(";").length;

and after this:

switch(whichScript)

{

case 1: {do something1; break;}

case 2: {do something2; break;}

...

case 3: {do something3; break;}

}