Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am using this code inside of a 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 wich which i can dynamically alter the number and types of the other controls?

share|improve this question
2  
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. –  Nasser Jul 7 at 1:19
1  
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. –  m_goldberg Jul 7 at 1:19
2  
@Nasser. You're right, but if we had the full code, someone could provide a work-around. –  m_goldberg Jul 7 at 1:21
1  
Somewhat related: 30003 and perhaps 40037 –  Michael E2 Jul 7 at 1:38
add comment

1 Answer 1

up vote 5 down vote accepted

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.

share|improve this answer
    
+1 -- Evidently Nasser and I were wrong in thinking one could not put a Switch in a Manipulate. –  m_goldberg Jul 7 at 2:03
3  
@m_goldberg you can put anything in Manipulate ...but you can always do it easier with DynamicModule ;) –  Mike Honeychurch Jul 7 at 2:59
    
@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. –  Nasser Jul 7 at 3:00
    
Thank you, that works. Could have sworn I tried using Dynamic myself and it didn't work but I must be mistaken. –  ChrisUnbroken Jul 7 at 14:57
    
@ChrisUnbroken You're welcome. I've certainly had that feeling, too. –  Michael E2 Jul 8 at 3:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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