Come posso cercare valori univoci nella colonna e utilizzarli nella finestra di input?Ho una tabella che assomiglia a questa, quello che vorrei fare è cercare valori univoci nella colonna "Colore tazza", quindi avere una finestra pop-up in cui l'utente può inserire un sapore corrispondente per ogni colore unico della tazza. .
| Colore della tazza | Calorie | Gusto | classifica | Tester |
| blu | 140 | 4 | 2 | 1 |
| verde | 80 | 7 | 1 | 4 |
| giallo | 200 | 2 | 3 | 6 |
| viola | 130 | 3 | 6 | 4 |
| blu | 140 | 3 | 5 | 2 |
| blu | 140 | 4 | 4 | 3 |
| giallo | 200 | 5 | 7 | 1 |
Una volta che abbiamo un sapore per ogni colore della tazza, vorrei aggiungere una nuova colonna che viene popolata in base all'input che abbiamo ricevuto dall'utente.
| Colore della tazza | Calorie | Gusto | classifica | Tester | Gusto |
| blu | 140 | 4 | 2 | 1 | ciliegia |
| verde | 80 | 7 | 1 | 4 | lampone |
| giallo | 200 | 2 | 3 | 6 | cioccolato |
| viola | 130 | 3 | 6 | 4 | davvero menta |
| blu | 140 | 3 | 5 | 2 | ciliegia |
| blu | 140 | 4 | 4 | 3 | ciliegia |
| giallo | 200 | 5 | 7 | 1 | cioccolato |
Sono ancora abbastanza nuovo in JSL e ho passato le ultime ore a esaminare i forum alla ricerca di una guida, ma non riesco a metterlo insieme, un piccolo aiuto sarebbe molto apprezzato.
Ri: Come posso cercare valori univoci nella colonna e utilizzarli nella finestra di input?L'uso di una finestra modale è un tipo di finestra davvero unico.Ci sono diverse regole che devi seguire.Uno dei quali coinvolge una casella di pulsanti con il testo di "OK".Ha una funzione speciale in una finestra modale.Quindi puoi usarli, ma dovrai studiarli e fare un po' di pratica con loro.
La mia preferenza è di non utilizzare le finestre modali, ma piuttosto di utilizzare gli elementi Functions() o Expr() per incapsulare il codice, impedendo che venga eseguito fino a quando lo script non indica che dovrebbe essere eseguito.Di seguito è riportato un semplice esempio di come farlo.
Names Default To Here( 1 );
// Get the list of unique colors
Summarize( dt, colorList = by( :Cup Color ) );
// Initialize the flavor list and make it the same
// length as the colorList
flavorList = {};
For( i = 1, i <= N Items( colorList ), i++,
Insert Into( flavorList, "" )
);
// Create the display window
nw = New Window( "Select Flavors",
//<< Modal,
Text Box( "Enter in Flavors for each Color" ),
tb = Table Box(
String Col Box( "Colors", colorList ),
scb = String Col Edit Box( "Flavors", flavorList )
),
Button Box( "OK",
nw << close window;
// Create the flavor table and update it to
// the original table
dt2 = New Table( "combined",
New Column( "Cup Color", character, set values( colorList ) ),
New Column( "Flavors", character, set values( flavorList ) )
);
dt << Update( With( dt2 ), Match Columns( :Cup Color = :Cup Color ) );
close( dt2, nosave );
runAdditionalCodePlease;
)
);
// Set the String Col Edit Box action
scb << Set Function( Function( {this, which}, flavorList[which] = scb << get( which ) ) );
runAdditionalCodePlease = Expr(
Dialog("This represents the kind of things that",
"you may want to run after the data entry.",
"By placing the code inside an Expr() or in",
"a Function(). The code will be run only",
"when executed within the code."
)
);Ri: Come posso cercare valori univoci nella colonna e utilizzarli nella finestra di input?In realtà ho bisogno che il mio script attenda l'input dell'utente prima di procedere.
Ho trovato nella guida allo scripting che posso farlo usando il messaggio modale e ho pensato di averlo aggiunto correttamente, ma quando eseguo lo script ora la tabella non si aggiorna - il registro dice "Nome non risolto: pulsante in accesso o valutazione di 'Button' , Button( 1 ) /*####*/"
// Get the list of unique colors
Summarize( dt, colorList = by( :Cup Color ) );
// Initialize the flavor list and make it the same
// length as the colorList
flavorList = {};
For( i = 1, i <= N Items( colorList ), i++,
Insert Into( flavorList, "" )
);
// Create the display window
nw = New Window( "Select Flavors",
<< Modal,
Text Box( "Enter in Flavors for each Color" ),
tb = Table Box(
String Col Box( "Colors", colorList ),
scb = String Col Edit Box( "Flavors", flavorList )
),
Button Box( "OK",
nw << close window;
// Create the flavor table and update it to
// the original table
dt2 = New Table( "combined",
New Column( "Cup Color", character, set values( colorList ) ),
New Column( "Flavors", character, set values( flavorList ) )
);
dt << Update( With( dt2 ), Match Columns( :Cup Color = :Cup Color ) );
close( dt2, nosave );
)
);
// Set the String Col Edit Box action
scb << Set Function( Function( {this, which}, flavorList[which] = scb << get( which ) ) );Ri: Come posso cercare valori univoci nella colonna e utilizzarli nella finestra di input?Perfetto grazie!Ri: Come posso cercare valori univoci nella colonna e utilizzarli nella finestra di input?Benvenuto nella comunità.
Innanzitutto, ho un suggerimento su come accelerare il tuo apprendimento di JSL.
Leggi la Guida allo scripting!!!!
È disponibile a
Aiuto==>Libri==>Guida allo scripting
Di seguito è riportato uno script barebone per realizzare ciò che hai richiesto.
Names Default To Here( 1 );
dt = New Table( "Untitled 2",
Add Rows( 7 ),
New Column( "Cup Color",
Character,
"Nominal",
Set Selected,
Set Values( {"blue", "green", "yellow", "purple", "blue", "blue", "yellow"} )
),
New Column( "Calories",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [140, 80, 200, 130, 140, 140, 200] )
),
New Column( "Taste",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [4, 7, 2, 3, 3, 4, 5] )
),
New Column( "Ranking",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [2, 1, 3, 6, 5, 4, 7] )
),
New Column( "Tester",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [1, 4, 6, 4, 2, 3, 1] )
)
);
// Get the list of unique colors
Summarize( dt, colorList = by( :Cup Color ) );
// Initialize the flavor list and make it the same
// length as the colorList
flavorList = {};
For( i = 1, i <= N Items( colorList ), i++,
Insert Into( flavorList, "" )
);
// Create the display window
nw = New Window( "Select Flavors",
Text Box( "Enter in Flavors for each Color" ),
tb = Table Box(
String Col Box( "Colors", colorList ),
scb = String Col Edit Box( "Flavors", flavorList )
),
Button Box( "OK",
nw << close window;
// Create the flavor table and update it to
// the original table
dt2 = New Table( "combined",
New Column( "Cup Color", character, set values( colorList ) ),
New Column( "Flavors", character, set values( flavorList ) )
);
dt << Update( With( dt2 ), Match Columns( :Cup Color = :Cup Color ) );
close( dt2, nosave );
)
);
// Set the String Col Edit Box action
scb << Set Function( Function( {this, which}, flavorList[which] = scb << get( which ) ) );