Compining temporäre variable names with integer

 

Hi,

I have declared a lot of variables like

int Varname1 = 5;

int Varname2 = 10;

int Varname3 = ...

Now I tried to convert my code with a for-loop automatically.

I tried this, but it doesn't work:

for(z=1; z<5;z++)
{
 var = pips2dbl * StrToDouble(StringConcatenate("Varname",DoubleToStr(z,0)));
 ...
}

If I write only :

(StringConcatenate("Varname",DoubleToStr(z,0))

the compiler is complaining, that it must be an integer an is only a string. But how can I do that the compiler realizes that f.g. Varname1 IS AN integer?!

 

it's not. Varname1 is a variable name not an integer. And

StringConcatenate("Varname",DoubleToStr(z,0)

is a string containing the letters "V", "a", "r", "n", "a", "m", "e", "1".

Read the book about arrays

int Varname[10];
Varname[1] = 5;
Varname[2] = 10;

for(z=1; z<5;z++){
  var = pips2dbl * Varname[z];
 
Lot's of thanks!!!!
 
Sorry, but how can I change that, if Varname[1] etc. must be extern values??
 
sunshineh:
Sorry, but how can I change that, if Varname[1] etc. must be extern values??

You could do this . . .

extern int variable1 = 1;
extern int variable2 = 2;
extern int variable3 = 3;
extern int variable4 = 4;
 .
 .
 .
 .

Varname[1] = variable1;
Varname[2] = variable2;
Varname[3] = variable3;
Varname[4] = variable4;
 

Yes, I did it in that way in my init-Function. Thank you!

Reason: