Link to home
Start Free TrialLog in
Avatar of k41d3n

asked on

changing the value in a ini file from an array

Alright, what I am looking to do is this:

I have a config.ini file that has the following bits here:

WebRefreshRate=1 (0 to 10 Minute(s))
AutoAnnResetMode=0 ( 0 - Disabled,  1 - Enabled)
BatteryChemistry=0 (0 - Lead-Acid, 1 - Nickel-Cadmium)
StringSetup=1 (0 - Silcon, 1 - Other), 1 (Number of Strings: 1 to 2), 40 (Batteries per String: 1 to 400), 6 (Cells per Battery: 1 to 6)
MonitorWireLength=0 (0 - 50 feet or less, 1 - Greater than 50 feet)
BatteryAHCapacity=100 (5 to 2000 AH)
CellVoltageLimitMinMax=2.150, 2.400 (2.000 to 2.500 V)
PilotTempLimitMax=95.0 F (30.0 to 140.0 F)
AmbientTempLimitMinMax=50.0, 95.0 F (30.0 to 140.0 F)
ChargeCurrentDeviationFromBenchmark=30 (0 to 100 %)
DischargeVoltageAlarmLevel=15 (5 to 20 %)
RippleCurrentAlarmLevel=5 (0 to 10 %)
InputContact1Name=Hydrogen Gas
InputContact1NormalState=0 (0 - Open, 1 - Closed)
InputContact2NormalState=0 (0 - Open, 1 - Closed)
InputContact1Delay=60 (0 to 300 Second(s))
InputContact2Delay=5 (0 to 300 Second(s))

each parameter has one value or several, I need a snippet of code that will set the values to varying variables, save it then set it to another variable.


CellVoltageLimitMinMax=2.150, 2.400 (2.000 to 2.500 V) can be set to any range between 2.000 and 2.500, I need to have a way to put the values in a file, or an array and some method open the file, change the value(s) to the first value, then run something I've already programmed, then set the values to the next bit and run the code, and the next etc;

I need to do this for each variable in the above block of code.

What is the best method to use?

Is it possible to do it with a properties file? becaus eI have a properties file and it would be benificial if the values could be changed without having to recompile the script.

Avatar of sumanraj

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If I understand your request correctly, you want a programmatic way of varying the values of each of the 18 variables one variable at a time throughout its domain of legal values, write this back to a new ini file and invoke a program you've already developed which will use this new ini file to perform some processing...

Discounting the fact that a couple of variables (InputContact1Name, InputContact2Name) don't seem to have a defined domain (maybe they're static and don't change), one of has multiple sub-variables ("StringSetup"), and one has an obvious limiting constraint... MAX probably is never less than MIN in AmbientTempLimitMinMax, with this many variables and the wide range of some of their domains, there are at least 4.5 x 10 ^ 27 combinations!   That's 45 followed by 26 zeros... If a single iteration took 1 second to complete, it would require about 1.5 x 10^20 YEARS!  It isn't practical... and I've probably under-calculated the number of combinations.

Hopefully, I've completely misconstrued what you were asking and you can clarify your request for all of us.  
Avatar of k41d3n


Actually, I figured it out and apologize for leaving this thread open.

I also meant to put this in the JAva programming section.

However, what I did was this:

In a properties file, I declared a list of keys(n) where n is a numerical increment. I put this entire set of keys into a vector. The keys, by the way, are constants in a ini file.

I also defined the variables I wanted to change each key to in the properties file.

So the program logic loads the vector of keys, and for each key it looks for possible variables in the properties file. it sets the variable in the config.ini and then runs the other program I made. Then sets the key to the next value etc; until all keys have been cycled.

It takes 14 minutes to run this process with roughly 30 keys. At most, in it's final iteration it will take a few hours. Which is nothing if you know automated softeare testing ;)