KenG Posted February 25, 2013 Share Posted February 25, 2013 I am having a problem using SendTo from a Variable Value to change an array value in a class more than one time. Here is the array ? unitconfig.answerconfig[currentanswer].coefficient {0, 0, -328.808990479, 0, -62.0190010071, 0, 246.9459991455, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} Write to element 0 unitconfig.answerconfig[currentanswer].coefficient[0] = 123.45 Result ? unitconfig.answerconfig[currentanswer].coefficient {123.45, 0, -328.808990479, 0, -62.0190010071, 0, 246.9459991455, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} Write element 0 a second time unitconfig.answerconfig[currentanswer].coefficient[0] = 999.87 ? unitconfig.answerconfig[currentanswer].coefficient 999.87 This does not happen from the command line. Weird! Link to comment Share on other sites More sharing options...
AzeoTech Posted February 25, 2013 Share Posted February 25, 2013 You can't have two sets of [] or () or combination inside one symbol specification. This is a bug in the OOP part of DAQFactory and part of the reason we haven't really publically released OOP. The workaround is to assign the first part to a temporary variable (assuming of course that its an object): private tempObject = unitConfig.answerConfig[currentAnswer] tempObject.coefficient[0] = 123.45 Note that this only works if answerConfig[currentAnswer] is an object because objects are passed by reference. Everything else is passed by value. Link to comment Share on other sites More sharing options...
KenG Posted February 25, 2013 Author Share Posted February 25, 2013 Thanks, I will try the work around. Here is the structure of the whole mess. class FactoryClass local ChannelEnables = 0 local PCAEnables = 0 local Filter = new(filters) local AnalogInput = new(AnalogInputs) local Turbidity = new(TurbidityReferences) local TECSetpoint = -10 local ProgramNumber = 1 endclass //global FactoryConfig = new(factoryClass) // Answer related // One Answer class AnswerClass local Enabled = 0 local string Name = "Answer Name" local Units = 0 local Baseline = {0,0} local Decimals = 1 local RangeMin = 0 local RangeMax = 1 local Averages = 1 local Constant = 0 local Coefficient = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} local Adjust = {0,1} function SetCoefficient(index,val) Coefficient[index] = val endfunction endclass // Configuration for a Unit Class UnitConfigclass local FactoryConfig = new(factoryClass) local AnswerConfig function OnCreate() AnswerConfig[0] = new(AnswerClass) AnswerConfig[1] = new(AnswerClass) AnswerConfig[2] = new(AnswerClass) AnswerConfig[3] = new(AnswerClass) AnswerConfig[4] = new(AnswerClass) AnswerConfig[5] = new(AnswerClass) AnswerConfig[6] = new(AnswerClass) AnswerConfig[7] = new(AnswerClass) AnswerConfig[8] = new(AnswerClass) AnswerConfig[9] = new(AnswerClass) AnswerConfig[10] = new(AnswerClass) AnswerConfig[11] = new(AnswerClass) endfunction endclass global UnitConfig = new(UnitConfigclass) Link to comment Share on other sites More sharing options...
AzeoTech Posted February 25, 2013 Share Posted February 25, 2013 Be careful with doing new() in a local declaration (i.e. local FactoryConfig = new(factoryClass). I'm not sure, but I think it will actually cause all your instantiated objects to reference the same object. Instead use an OnCreate() to do that sort of initialization. Also, in that OnCreate for UnitConfigClass, consider using a for() loop. It'd be much cleaner. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.