cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
frankzhao
Level II

How to multiple select values from one column and subset them?

I have a table which  include a column named 'PCO',

In this column,there are lots of different values,such as 'PCO1','PCO2',...............'PCON',

I want to select the rows include  'PCO1' or 'PCO2' or 'PCO3' and subset them,

but the situation is that I want to use a string that

strPCO=="PCO1","PCO2","PCO3", to select values

so I write a script like:

data_table = open (DATA_PATH)

PCO_CONDITION = {"PCO1","PCO2","PCO3"};

for (i=1,i<=n items(PCO_CONDITION),i++,

  data_table<<select where (:PCO ==PCO_CONDITION)

);

dt=data_table<<subset (selected rows);

this script cant work,can anybody tell me how to deal with it?

Thanks guys

1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: How to multiple select values from one column and subset them?

Use Or(), or here even better, Contains() to match any of the three conditions instead of one at a time.

Example:

//Example table

data_table = newtable("test", newcolumn("PCO", character,

values(Repeat(i=0;{i++ ; "PCO" || Char( Mod( i-1 , 5 )+1 )}, 25 )))

  );

// Make conditional subset

PCO_CONDITION = {"PCO1","PCO2","PCO3"};

data_table<<select where(Contains(PCO_CONDITION,:PCO));

dt=data_table<<subset (selected rows);

View solution in original post

5 REPLIES 5
frankzhao
Level II

Re: How to multiple select values from one column and subset them?

In addition,I want make all rows include these 3 PCOs into a subset,but now my script can only select the last one.

ms
Super User (Alumni) ms
Super User (Alumni)

Re: How to multiple select values from one column and subset them?

Use Or(), or here even better, Contains() to match any of the three conditions instead of one at a time.

Example:

//Example table

data_table = newtable("test", newcolumn("PCO", character,

values(Repeat(i=0;{i++ ; "PCO" || Char( Mod( i-1 , 5 )+1 )}, 25 )))

  );

// Make conditional subset

PCO_CONDITION = {"PCO1","PCO2","PCO3"};

data_table<<select where(Contains(PCO_CONDITION,:PCO));

dt=data_table<<subset (selected rows);

frankzhao
Level II

Re: How to multiple select values from one column and subset them?

Thanks,I have another trouble here,I have a txtbox like this :

7429_Capture.JPG

now my script is :

Panel Box ("PCO",

     lineup box (N col( 1 ),Spacing ( 3 ),

     //PCOcheck = check box({"Type in PCO"},PCO << enable (PCOcheck << Get ())),

     PCO = text edit box("", << enable ( 1 ),

     <<set script( txtPCO = PCO << Get Text();

                    ),<< set width (240),<<set N lines(5)),

But how can I get a string like ("PCO1","PCO2","PCO3") from input?

pmroz
Super User

Re: How to multiple select values from one column and subset them?

You have to parse them out of the text edit box using words and a carriage return + line feed delimiter:

nw = New Window( "Example",

    Panel Box( "PCO",

        Lineup Box( N Col( 1 ), Spacing( 3 ),

            pco_teb = Text Edit Box( "",

<<set width( 240 ),

<<set N lines( 5 )

            ),

        )

    ),

    button box("OK",

        pco_text = pco_teb << get text;

// Create a delimiter consisting of a carriage return + line feed

        crlf     = hex to char("0D0A");

// Parse the list into separate words

        pco_list = words(pco_text, crlf);       

        nW << close window;

    );

);

frankzhao
Level II

Re: How to multiple select values from one column and subset them?

Thank you