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 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.

share|improve this question
    
I don't understand the code very well… but I think a semicolon is needed before Panel. –  xzczd Sep 11 '12 at 7:05
    
@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. –  Jennifer Sep 11 '12 at 7:22
    
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. –  xzczd Sep 11 '12 at 9:08
    
@xzczd: yes. It gives the value when both the arguments tx and symbol are removed from the defined functions. –  Jennifer Sep 11 '12 at 9:09
add comment

1 Answer 1

up vote 2 down vote accepted

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")]]}])
share|improve this answer
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.