Thank you, Don. That works great!

I had tried setfield! earlier, but I was doing: setfield!(inst, 
varToChange, 20) and was (obviously) getting error. 

I wonder why this is not automatically done by setfield!

On Saturday, September 13, 2014 8:06:31 PM UTC-4, Don MacMillen wrote:
>
> setfield!(inst, symbol(varToChange), 20)
>
> On Saturday, September 13, 2014 4:47:46 PM UTC-7, [email protected] 
> wrote:
>>
>>
>> Hi All,
>>
>> Suppose I have a composite type and an instance of it:
>>
>> type myType
>>            numLines::Int
>>            avgLength::Float64
>>        end
>>
>> inst = myType(10, 8.5)
>>
>>
>> I want to change, say numLines of inst1 to 20. I know I can do 
>>  
>>
>> inst.numLines = 20
>>
>>
>> However, suppose the field that has to be changed is determined by the 
>> program. Say, I have, 
>>
>> varToChange = "numLines"
>>
>> How can I use *varToChange* to change the value of *numLines* in *inst*? 
>>
>> Thank you.
>>
>>
>>
>>

Reply via email to