In the following script I have a list of 3 elements and I am trying to create a new window where the user can enter some values for each of the elements:
myList = {"apple", "banana", "orange"};
nw = New Window( "Enter Numbers",
<<Modal,
<<Return Result,
V List Box(
Text Box("Enter the values"),
For( i = 1, i <= N Items( myList ), i++,
Lineup Box( Text Box( Eval(myList[i])),
Number Edit Box( 42 )
)
),
H List Box(
Button Box( "OK" ),
Button Box( "Cancel" )
)
)
);I use the for loop because the number of the items in the list "myList" changes. So that I would like to happen also for the Number Edit Boxes. However, I get back the following:
Ideally I would like the values that the end user enters to be saved in a list.
Here is the approach that I would take
Names Default To Here( 1 );
myList = {"apple", "banana", "orange"};
myVList = V List Box(
Text Box( "Enter the values" ),
lub = Lineup Box( N Col( 2 ), ),
H List Box( Button Box( "OK" ), Button Box( "Cancel" ) )
);
For Each( {box}, myList,
lub << append( Text Box( Eval( box ) ) );
lub << append( Number Edit Box( 42 ) );
);
nw = New Window( "Enter Numbers",
<<Modal,
<<Return Result,
myVlist
);
Multiple different ways how you can do this.
You can use different methods of collecting the results, you can use XPath
Names Default To Here(1);
fruits = {"apple", "banana", "orange"};
value_collector = V List Box(
Text Box("Enter the values"),
lub = Lineup Box(N Col(2))
);
For Each({fruit}, fruits,
lub << append(Text Box(fruit));
lub << append(Number Edit Box(42));
);
nw = New Window("Enter Numbers", <<Modal, <<Return Result,
V List Box(
value_collector,
H List Box(
Button Box("OK",
vals = (lub << XPath("//NumberEditBox")) << get;
),
Button Box("Cancel")
)
)
);
If(nw["Button"] != 1,
Throw("Cancelled")
);
Show(fruits, vals);
or store the references to a list
Names Default To Here(1);
fruits = {"apple", "banana", "orange"};
value_collector = V List Box(
Text Box("Enter the values"),
lub = Lineup Box(N Col(2))
);
nebs = {};
For Each({fruit}, fruits,
lub << append(Text Box(fruit));
lub << append(neb = Number Edit Box(42));
Insert Into(nebs, neb);
);
nw = New Window("Enter Numbers", <<Modal, <<Return Result,
V List Box(
value_collector,
H List Box(
Button Box("OK",
vals = nebs << get;
),
Button Box("Cancel")
)
)
);
If(nw["Button"] != 1,
Throw("Cancelled")
);
Show(fruits, vals);
or associative array
Names Default To Here(1);
fruits = {"apple", "banana", "orange"};
value_collector = V List Box(
Text Box("Enter the values"),
lub = Lineup Box(N Col(2))
);
vals = Associative Array();
For Each({fruit}, fruits,
lub << append(Text Box(fruit));
lub << append(neb = Number Edit Box(42));
vals[fruit] = neb;
);
nw = New Window("Enter Numbers", <<Modal, <<Return Result,
V List Box(
value_collector,
H List Box(
Button Box("OK",
res = Associative Array(vals << get keys, (vals << get values) << get);
),
Button Box("Cancel")
)
)
);
If(nw["Button"] != 1,
Throw("Cancelled")
);
Show(fruits, vals, res);
With these you will have UI something like this
Or you could utilize totally different display box elements (table box and number col edit box)
Names Default To Here(1);
fruits = {"apple", "banana", "orange"};
nw = New Window("Enter Numbers", <<Modal, <<Return Result,
V List Box(
Text Box("Enter the values:"),
Table Box(
String Col Box("Fruit", fruits),
nceb = Number Col Edit Box("Value", J(N Items(fruits), 1, 42)),
),
H List Box(
Button Box("OK"),
Button Box("Cancel")
)
)
);
If(nw["Button"] != 1,
Throw("Cancelled")
);
show(nw["nceb"]);
Here is the approach that I would take
Names Default To Here( 1 );
myList = {"apple", "banana", "orange"};
myVList = V List Box(
Text Box( "Enter the values" ),
lub = Lineup Box( N Col( 2 ), ),
H List Box( Button Box( "OK" ), Button Box( "Cancel" ) )
);
For Each( {box}, myList,
lub << append( Text Box( Eval( box ) ) );
lub << append( Number Edit Box( 42 ) );
);
nw = New Window( "Enter Numbers",
<<Modal,
<<Return Result,
myVlist
);
Multiple different ways how you can do this.
You can use different methods of collecting the results, you can use XPath
Names Default To Here(1);
fruits = {"apple", "banana", "orange"};
value_collector = V List Box(
Text Box("Enter the values"),
lub = Lineup Box(N Col(2))
);
For Each({fruit}, fruits,
lub << append(Text Box(fruit));
lub << append(Number Edit Box(42));
);
nw = New Window("Enter Numbers", <<Modal, <<Return Result,
V List Box(
value_collector,
H List Box(
Button Box("OK",
vals = (lub << XPath("//NumberEditBox")) << get;
),
Button Box("Cancel")
)
)
);
If(nw["Button"] != 1,
Throw("Cancelled")
);
Show(fruits, vals);
or store the references to a list
Names Default To Here(1);
fruits = {"apple", "banana", "orange"};
value_collector = V List Box(
Text Box("Enter the values"),
lub = Lineup Box(N Col(2))
);
nebs = {};
For Each({fruit}, fruits,
lub << append(Text Box(fruit));
lub << append(neb = Number Edit Box(42));
Insert Into(nebs, neb);
);
nw = New Window("Enter Numbers", <<Modal, <<Return Result,
V List Box(
value_collector,
H List Box(
Button Box("OK",
vals = nebs << get;
),
Button Box("Cancel")
)
)
);
If(nw["Button"] != 1,
Throw("Cancelled")
);
Show(fruits, vals);
or associative array
Names Default To Here(1);
fruits = {"apple", "banana", "orange"};
value_collector = V List Box(
Text Box("Enter the values"),
lub = Lineup Box(N Col(2))
);
vals = Associative Array();
For Each({fruit}, fruits,
lub << append(Text Box(fruit));
lub << append(neb = Number Edit Box(42));
vals[fruit] = neb;
);
nw = New Window("Enter Numbers", <<Modal, <<Return Result,
V List Box(
value_collector,
H List Box(
Button Box("OK",
res = Associative Array(vals << get keys, (vals << get values) << get);
),
Button Box("Cancel")
)
)
);
If(nw["Button"] != 1,
Throw("Cancelled")
);
Show(fruits, vals, res);
With these you will have UI something like this
Or you could utilize totally different display box elements (table box and number col edit box)
Names Default To Here(1);
fruits = {"apple", "banana", "orange"};
nw = New Window("Enter Numbers", <<Modal, <<Return Result,
V List Box(
Text Box("Enter the values:"),
Table Box(
String Col Box("Fruit", fruits),
nceb = Number Col Edit Box("Value", J(N Items(fruits), 1, 42)),
),
H List Box(
Button Box("OK"),
Button Box("Cancel")
)
)
);
If(nw["Button"] != 1,
Throw("Cancelled")
);
show(nw["nceb"]);