2
$\begingroup$

I have a lesson notebook for a class I am teaching. I'd like to separate the lesson content and the practice problems. Students are using the CDFPlayer program, not Mathematica.

I created a button that will open a specific notebook…

Button[
  "open",
  NotebookOpen[FileNameJoin[{NotebookDirectory[ButtonNotebook[]], "sample.nb"}]]]

and this works fine in the CDFPlayer.

However, selecting a "random" question from a list of files doesn't. Something in my code doesn't work in the free player. (The same code works fine in Mathematica)

This is what I tried:

Button[
  "open",
  NotebookOpen[RandomChoice[FileNames[{"*.nb"}, {NotebookDirectory[ButtonNotebook[]]}]]]]

I'm wondering if someone could offer a suggestion? I'd like a button that when clicked, will open a notebook from a folder of practice problems, and work in the CDFPlayer.

Any suggestions are appreciated.

I see (and appreciate) the feedback that the free CDFPlayer is NOT able to open files. So that answers my question...

$\endgroup$
3
  • 1
    $\begingroup$ You can't use free CDF to open files. mathematica.stackexchange.com/questions/8929/… if that is what you are trying to do. You'd need the pro CDF for that. $\endgroup$
    – Nasser
    Commented Dec 26, 2013 at 7:45
  • 1
    $\begingroup$ I don't know much about what is OK on the free CDFPlayer, but maybe FileNames[{"*.nb"} is disallowed because it looks as if you were fishing for what files are available. Try Button["open", Print @ RandomChoice[FileNames[{"*.nb"}, {NotebookDirectory[ButtonNotebook[]]}]]]. It might give you more insight. $\endgroup$
    – m_goldberg
    Commented Dec 26, 2013 at 8:31
  • $\begingroup$ Thanks for those comments, and that information. It makes sense that CDFPlayer would not be able to "fish" for file names and open one. I'd still like to find a solution that would choose a question at random, but I can simply link to the files. So my question is answered…. $\endgroup$ Commented Dec 26, 2013 at 9:29

1 Answer 1

1
$\begingroup$

HI… I found I could get this to work using a SUPPLIED list of questions. I WILL know ahead of time how many questions there are, so I didn't need to "fish" for the file names.

I just put the questions in a folder with nice sequential names, Q1, Q2, Q3, etc. and used the following (which works fine in the free CDFPlayer)

Button["open",
 NotebookOpen[
  FileNameJoin[{
    NotebookDirectory[EvaluationNotebook[]],
    "Data",
    "Questions",
    RandomChoice["Q " <> ToString[#] <> ".nb" & /@ Range[3]]}]]]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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