Message Boards Message Boards

0
|
4455 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

Change a value internally to a raw object?

Posted 8 years ago

Hello, I am working on an application where user inputs some values/function. For some cases I need to change the value internally. But I get an error cannot assign to raw object. What is the way around this problem ? I am sure there is but I just could not find one. ( I am aware that n there is not really n it is a number. That is why I can't do 8=10. )

Here is an simple mini-code

Get[FileNameJoin[{NotebookDirectory[EvaluationNotebook[]], 
    "Trialpackage.wl"}]];
DynamicModule[{n = 16, R = 32}, Column[{
   Row[{Style["Number of Digits", 12, Black], 
     InputField[Dynamic[n], Number, FieldSize -> 5]}, Spacer[5]],
   Button[Style["Calculate", 14, Green, Bold], 
    R = Trialpackage`dummyfunc[n]],
   Row[{Style["Result", 12, Red], InputField[Dynamic[R]]}, 
    Spacer[15]]}],

 Initialization :> (
   Get[FileNameJoin[{NotebookDirectory[EvaluationNotebook[]], 
      "Trialpackage.wl"}]]

   )
 ]

and the package is

BeginPackage["Trialpackage`"]
dummyfunc::usage="";
Begin["`Private`"]
dummyfunc[n_]:=Module[{f,b},
f=3;
b=6;
If[n<10,Clear[n]; n=16];
Print[n];
res=n*f*b;
Return[res];]
End[];
SetAttributes[{dummyfunc},{ReadProtected,Protected,Locked}];
EndPackage[];
POSTED BY: Erdem Uguz
Posted 8 years ago

I found a way to deal with it but I am not sure if this is the best way of doing it. I simply change the name of n to n1 and with an if statement I define n .

BeginPackage["Trialpackage`"]
dummyfunc::usage="";
Begin["`Private`"]
dummyfunc[n1_]:=Module[{f,b,new},
f=3;
b=6;
n=0;
If[n1<10, n=16, n=n1; ];
Print[n];
res=n*f*b;
Return[res];]
End[];
SetAttributes[{dummyfunc},{ReadProtected,Protected,Locked}];
EndPackage[];
POSTED BY: Erdem Uguz
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