Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #14493 > unrolled thread
| Started by | Dushan Mitrovich <dushanm@nnips.net> |
|---|---|
| First post | 2013-05-14 07:14 +0000 |
| Last post | 2013-05-18 06:38 +0000 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
can't get InputField to work inside a While command Dushan Mitrovich <dushanm@nnips.net> - 2013-05-14 07:14 +0000
Re: can't get InputField to work inside a While command David Bailey <dave@removedbailey.co.uk> - 2013-05-15 06:53 +0000
Re: can't get InputField to work inside a While command Dushan Mitrovich <dushanm@nnips.net> - 2013-05-17 08:34 +0000
Re: can't get InputField to work inside a While command David Bailey <dave@removedbailey.co.uk> - 2013-05-18 06:38 +0000
| From | Dushan Mitrovich <dushanm@nnips.net> |
|---|---|
| Date | 2013-05-14 07:14 +0000 |
| Subject | can't get InputField to work inside a While command |
| Message-ID | <kmso9j$h67$1@smc.vnet.net> |
I need to be able to input parameters for an a-priori indeterminate number of cases. The way I've been trying to do this is by using a While statement containing InputFields, one of which asks if there are to be more cases to deal with. If not, the previously True logical 'test' for While is reset to False. But apparently InputField is not even recognized as part of the 'body' inside a While. By itself InputField works as expected, but not in this reduced example: cntr = 0; While[cntr<3, cntr++; InputField[xx]] which only produces 1 2 3 What am I missing? Or am I going about this the wrong way? - Dushan [ reverse the middle word of address to reply ]
[toc] | [next] | [standalone]
| From | David Bailey <dave@removedbailey.co.uk> |
|---|---|
| Date | 2013-05-15 06:53 +0000 |
| Message-ID | <kmvbdl$nok$1@smc.vnet.net> |
| In reply to | #14493 |
On 14/05/2013 08:14, Dushan Mitrovich wrote:> I need to be able to input
parameters for an a-priori indeterminate
> number of cases. The way I've been trying to do this is by using a
> While statement containing InputFields, one of which asks if there are
> to be more cases to deal with. If not, the previously True logical
> 'test' for While is reset to False.
>
> But apparently InputField is not even recognized as part of the 'body'
> inside a While. By itself InputField works as expected, but not in this
> reduced example:
>
> cntr = 0;
> While[cntr<3, cntr++; InputField[xx]]
>
> which only produces
>
> 1
> 2
> 3
>
> What am I missing? Or am I going about this the wrong way?
>
> - Dushan
> [ reverse the middle word of address to reply ]
>
You need to realise the InputField construction generates a box only
when it is output to a notebook (analogous to a Graphics object) - it
doesn't evaluate to anything other than itself. This code will create a
list of InputField objects, each attached to a different element of a
list, and the result will be returned to your notebook as a column of
boxes so you can change the various components and observe the result by
evaluating the variable data.
nin=7;
data=ConstantArray[0,nin];
Column[Table[With[{k=k},InputField[Dynamic[data[[k]]]]],{k,1,7}]]
This may, or may not be what you really want. You may want to place the
InputField objects in a separate, pop-up notebook with a close button to
close the window before the program continues to execute. This is
possible using CreateDialog.
David Bailey
http://www.dbaileyconsultancy.co.uk
[toc] | [prev] | [next] | [standalone]
| From | Dushan Mitrovich <dushanm@nnips.net> |
|---|---|
| Date | 2013-05-17 08:34 +0000 |
| Message-ID | <kn4q33$2b5$1@smc.vnet.net> |
| In reply to | #14500 |
David Bailey wrote:
> On 14/05/2013 08:14, Dushan Mitrovich wrote:> I need to be able to input
> parameters for an a-priori indeterminate
> > number of cases. The way I've been trying to do this is by using a
> > While statement containing InputFields, one of which asks if there are
> > to be more cases to deal with. If not, the previously True logical
> > 'test' for While is reset to False.
> >
> > But apparently InputField is not even recognized as part of the 'body'
> > inside a While. By itself InputField works as expected, but not in this
> > reduced example:
> >
> > cntr = 0;
> > While[cntr<3, cntr++; InputField[xx]]
> >
> > which only produces
> >
> > 1
> > 2
> > 3
> >
> > What am I missing? Or am I going about this the wrong way?
> >
> > - Dushan
> > [ reverse the middle word of address to reply ]
> >
>
> You need to realise the InputField construction generates a box only
> when it is output to a notebook (analogous to a Graphics object) - it
> doesn't evaluate to anything other than itself. This code will create a
> list of InputField objects, each attached to a different element of a
> list, and the result will be returned to your notebook as a column of
> boxes so you can change the various components and observe the result by
> evaluating the variable data.
>
> nin=7;
> data=ConstantArray[0,nin];
> Column[Table[With[{k=k},InputField[Dynamic[data[[k]]]]],{k,1,7}]]
>
> This may, or may not be what you really want. You may want to place the
> InputField objects in a separate, pop-up notebook with a close button to
> close the window before the program continues to execute. This is
> possible using CreateDialog.
>
> David Bailey
> http://www.dbaileyconsultancy.co.uk
>
>
Okay, thanks for the clarification. It seems I can't use InputField the
way I intended in a loop testing for a condition. Your example assumes
I know beforehand the number of times I need to invoke it, which
generally won't be the case.
But apparently I can use Input within such a loop, and I'll explore that
possibility further.
- Dushan
[toc] | [prev] | [next] | [standalone]
| From | David Bailey <dave@removedbailey.co.uk> |
|---|---|
| Date | 2013-05-18 06:38 +0000 |
| Message-ID | <kn77lc$8j7$1@smc.vnet.net> |
| In reply to | #14519 |
On 17/05/2013 09:34, Dushan Mitrovich wrote:> Okay, thanks for the
clarification. It seems I can't use InputField the
> way I intended in a loop testing for a condition. Your example assumes
> I know beforehand the number of times I need to invoke it, which
> generally won't be the case.
>
> But apparently I can use Input within such a loop, and I'll explore that
> possibility further.
Well, I went on to point out that perhaps you would like to use a
separate window - for example:
cntr = 0;
While[cntr < 3,
cntr++;
xx = 0;
DialogInput[Column[{InputField[Dynamic[xx]], DefaultButton[]}],
WindowTitle -> "Enter xx"];
]
This will create a popup box on each turn of the loop, and pause until
you respond and dismiss the box.
You can create a lot with these function that generate dynamic elements
and popup notebooks, etc., but I would be the first to agree that they
aren't very intuitive to use!
David Bailey
http://www.dbaileyconsultancy.co.uk
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web