Message Boards Message Boards

0
|
5863 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How can I request input from the user in a package?

Posted 10 years ago

Hi,

I am wondering how to request and accept input from an user in package. For example, I want to write a package that requires the user to specify the path to a given file or directory. In Summary I'd like to:

  • Have the user specify the file through an Input Field
  • Import that file
  • Do something with that file

Thus far I've tried:

BeginPackage["Analysis`"]  
 getFile::usage= "getFile[] imports the user specified file."  

Begin["`Private`"]  
 getFile[___]:=getFile=InputField["Enter the data directory"];   
End[];    
EndPackage[];

But this does not work as expected. When I call the package in a notebook and call the function getFile[] the dialog box gets created as an output cell instead of an input cell. What is a better and more robust method to request user input and assign that input to variables via a package?

Thanks for your help

POSTED BY: Pat Mac
2 Replies
Posted 10 years ago

Excellent! Up and running. Thank you!

POSTED BY: Pat Mac
Posted 10 years ago

This is because there is no Dialog in your code. This has nothing to do with the package. You call the function later, right?

So use Input, DialogInput or probably better suited for this job FileNameSetter.

POSTED BY: Kuba Podkalicki
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract