How to run the procedure in the variable

My sketch as bellow:

#include “HX711.h”
#include <Wire.h>
HX711 scale0(A1, A0);
HX711 scale1(A3, A2);
HX711 scale2(A5, A4);
HX711 scale3(A7, A6);
int calibration_factor[4] = {1026,1041,1004,-1881};
String Scalestr = “scale”;
String Scale[14];
String Tare[14];
void setup()
{
{
void loop()
{
for( int i=0;i<4;si++)
{
Scale[scalenum] = Scalestr+scalenum+".set_scale(calibration_factor["+scalenum+"]";
Tare[scalenum] = Scalestr+scalenum+".tare()";
Scale[scalenum];
Tare[scalenum];
}
}

I want to run command :
scale0.set_scale(calibration_factor[0]);
scale0.tare();
scale1.set_scale(calibration_factor[1]);
scale1.tare();
scale2.set_scale(calibration_factor[2]);
scale2.tare();
scale3.set_scale(calibration_factor[3]);
scale3.tare();

I call the variable with content is front command, but it can’t,
Please show me how to run it in the for command,
Rgs
Reed.

Reednoel4u:
My sketch as bellow:

#include “HX711.h”
#include <Wire.h>
HX711 scale0(A1, A0);
HX711 scale1(A3, A2);
HX711 scale2(A5, A4);
HX711 scale3(A7, A6);
String Scalestr = “scale”;
String Scale[14];
String Tare[14];
void setup()
{
{
void loop()
{
for( int i=0;i<4;si++)
{
Scale[scalenum] = Scalestr+scalenum+".set_scale(calibration_factor["+scalenum+"]";
Tare[scalenum] = Scalestr+scalenum+".tare()";
Scale[scalenum];
Tare[scalenum];
}
}

I want to run command :
scale0.set_scale(calibration_factor[0]);
scale0.tare();
scale1.set_scale(calibration_factor[1]);
scale1.tare();
scale2.set_scale(calibration_factor[2]);
scale2.tare();
scale3.set_scale(calibration_factor[3]);
scale3.tare();

I call the variable with content is front command, but it can’t,
Please show me how to run it in the for command,
Rgs
Reed.

Please help…

I want to run command :
scale0.set_scale(calibration_factor[0]);

I can't see an array called "calibration_factor", so I think you've not posted all of your code.

I don't understand what you are trying to do.

TolpuddleSartre:
I can't see an array called "calibration_factor", so I think you've not posted all of your code.

I don't understand what you are trying to do.

Sorry, I mistake the line:
int calibration_factor[4];// = {1026,1041,1004,970,1041,1023,1005,998,1000,-2015,1024,1022,1014,-1881};
The code so long, I just post where the make some not right.
When I using for() command, this code so short, If i using many scale, the code so long!
Reed.

I still can't understand what it is you want to do.
It looks like you're trying to mangle function names and indexes.
I think you need an array of functions, but it is very hard to tell.

int calibration_factor[4];// = {1026,1041,1004,970,1041,1023,1005,998,1000,-2015,1024,1022,1014,-1881};Please promise me that you will not remove the semicolon and comment markers in the middle of that line

TolpuddleSartre:
I think you need an array of functions, but it is very hard to tell.

More likely, an array of 'HX711' objects.

Reednoel4u:
The code so long, I just post where the make some not right.

Post the complete program. Add it as an attachment if it is too long to include. Or, better still, write a short program that illustrates the problem.

If you could identify the part of your program which is causing the problem you would probably have found the problem.

...R

Variables do NOT have names at run time. Expecting to construct a String like "scale0.set_scale(calibration_factor[0]);" and then being able to call the set_scale() method for the scale0 object is completely unrealistic.

Create an array of scale objects. Then you can iterate over the array, using a for loop, and call the scale[ i ].set_scale() method.