1
$\begingroup$

I have defined a function

logicalInputField[i_, fieldSize_, numberOfFields_, enable_,tx_,symbol_] :=
Column[{InputField[Dynamic[tx[[i]]], Number, ImageSize -> fieldSize, 
Enabled -> enable, ContinuousAction -> True],
  Dynamic[If[TrueQ[tx[[i]] == ""],                   
     (symbol[[i]] = "Please Enter"),(symbol[[i]] ="Right")                                                                           
  ]  ]}] 

I am calling this function here.

DynamicModule[
{s = {}},
 For[i = 1, i <= 3, i++,
     With[{i = i},AppendTo[s, logicalInputField[i, {50, 20}, 3, True,{"", "", ""}, {"Please Enter", "Please Enter", "Please Enter"}]]]];
     Panel[ Row[s]]]

I want to ask whenever I am not giving tx and symbol as an argument at the time of defining function. and then calling it, it works fine. But, as soon as I enter some value in InputField , it gives error message

Set::setps: {, ,} in the part assignment is not a symbol.

Why? How can I call the Part of a variable from the user defined function.

$\endgroup$
  • $\begingroup$ I don't understand the code very well… but I think a semicolon is needed before Panel. $\endgroup$ – xzczd Sep 11 '12 at 7:05
  • $\begingroup$ @xzczd: This code is just a sample but I want to ask how can I call the Part of the list. Here symbol and tx are the lists. So, how can I call these variables from the function. I guess this is a wrong way of calling. Therefore, I am getting error. $\endgroup$ – Jennifer Sep 11 '12 at 7:22
  • $\begingroup$ I think I get one of the point: If[TrueQ[tx[[i]] == ""], (symbol[[i]] = "Please Enter"),(symbol[[i]] ="Right") ]doesn't give back a value.symbol[[i]] =should be deleted here. $\endgroup$ – xzczd Sep 11 '12 at 9:08
  • $\begingroup$ @xzczd: yes. It gives the value when both the arguments tx and symbol are removed from the defined functions. $\endgroup$ – Jennifer Sep 11 '12 at 9:09
2
$\begingroup$

The real reason for the error is that symbol and tx is no longer two variables but two lists once the function is called. In fact the error Set::setps: {, ,} in the part assignment is not a symbol. can be reproduced when changing the first part of your code as the following:

logicalInputField[i_, fieldSize_, numberOfFields_, enable_, tx_, symbol_] := (tx[[i]] = 3)

It can even be reproduced by:

f[x_] := (x[[1]] = 2)
f[{2}]

It generates errors because (tx[[i]] = "3") is actually "" = 3 here, and "" isn't a symbol so it can't be given a value. This can be proved by:

f[x_] := (y = x; Print@Hold@y; Print@Hold@x)
f[{2}]

    (*=> Hold[y]

         Hold[{2}]*)

Well, it seems to be a neglected (at least by you and me…) property of the argument of a function…

The problem can be solved by using intermediate variables in the function, here is the solution:

logicalInputField[i_, fieldSize_, numberOfFields_, enable_, tx_, symbol_] := 

(txtx = tx; sysy = symbol; 

 Column[{InputField[Dynamic[txtx[[i]]], Number, ImageSize -> fieldSize, 
                    Enabled -> enable, ContinuousAction -> True], 
         Dynamic[If[TrueQ[txtx[[i]] == ""], (sysy[[i]] ="Please Enter"), (sysy[[i]] ="Right")]]}])
$\endgroup$

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.