9
$\begingroup$

I am using this code inside Manipulate:

Switch[cases, 
     "custom", Control[{{names, True}, {True, False}}],
     "a", Control[{{slide, 0}, 0, 1}],
     "b", Control[{{setter, "das"}, {"das", "der", "die"}}]],
    {{cases, "custom"}, {"custom", "a", "b"}}

The variable cases is supposed to control which other control type is visible. However i get the following error message:

Manipulate::vsform: Manipulate argument Switch[cases,

[...]

does not have the correct form for a variable specification. >>

[...] is a placeholder which in mathematica displays the controls i specified above (Odd, right?). I cannot post screenshots yet unfortunately. Does anybody have an idea why this isn't working or how to better implement a manipulate control in which I can dynamically alter the number and types of the other controls?

$\endgroup$
4
  • 2
    $\begingroup$ You can't do this. You can't put controls inside Switch, at least I never seen it before. But if you post full code, it will help try it out than spend time to try to recreate it. $\endgroup$
    – Nasser
    Jul 7, 2014 at 1:19
  • 1
    $\begingroup$ It would be helpful to those who would like answer your question to have your full Manipulate expression and support code it depends on. Please edit your question by adding that code. $\endgroup$
    – m_goldberg
    Jul 7, 2014 at 1:19
  • 2
    $\begingroup$ @Nasser. You're right, but if we had the full code, someone could provide a work-around. $\endgroup$
    – m_goldberg
    Jul 7, 2014 at 1:21
  • 1
    $\begingroup$ Somewhat related: 30003 and perhaps 40037 $\endgroup$
    – Michael E2
    Jul 7, 2014 at 1:38

1 Answer 1

10
$\begingroup$

Perhaps this?

Manipulate[
  {names, slide, setter, cases},
  Dynamic@Switch[cases,
    "custom", Control[{{names, True}, {True, False}}],
    "a", Control[{{slide, 0}, 0, 1}],
    "b", Control[{{setter, "das"}, {"das", "der", "die"}}]], 
  {{cases, "custom"}, {"custom", "a", "b"}}]

The variables seem to get localized properly even though the syntax coloring is wrong.

$\endgroup$
5
  • $\begingroup$ +1 -- Evidently Nasser and I were wrong in thinking one could not put a Switch in a Manipulate. $\endgroup$
    – m_goldberg
    Jul 7, 2014 at 2:03
  • 3
    $\begingroup$ @m_goldberg you can put anything in Manipulate ...but you can always do it easier with DynamicModule ;) $\endgroup$ Jul 7, 2014 at 2:59
  • $\begingroup$ @m_goldberg But I qualified it by saying "at least I never seen it before." :) I was lazy to actually try it. But I learned something new today about Manipulate. $\endgroup$
    – Nasser
    Jul 7, 2014 at 3:00
  • $\begingroup$ Thank you, that works. Could have sworn I tried using Dynamic myself and it didn't work but I must be mistaken. $\endgroup$
    – Christian
    Jul 7, 2014 at 14:57
  • $\begingroup$ @ChrisUnbroken You're welcome. I've certainly had that feeling, too. $\endgroup$
    – Michael E2
    Jul 8, 2014 at 3:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.