a noobie question - help please

 

Hi there

Im not asking for code , just a point in the right direction:

I need to define a changing variable, kinda hard to explain , so Ive sort've coded it:

 

extern int number= 'xxx';       // user input 1/2/3 . . etc

. . . .  

    double value1 = OrdersTotal();

   double value2 =OrdersTotal();

   double value3 = OrdersTotal();

 . . . 

if value(  number  ) . . .   //this would be value1 or value2 or value3 asdefined by the extern int number= 'xxx';

 

thanx so much 

 

It's difficult to work out exactly what you are asking.

Read the documentation for arrays, maybe that is what you mean? 

 

If I understand what you want correctly, you want a user input which chooses which variable gets used in later calculations?

If so, you can't do that directly. You'd need to use a switch or if statement. 

enum variables
  {
   value1, // Use MyVal1
   value2, // Use MyVal2
   value3  // Use MyVal3
  };
extern variables number = value1;

void OnTick()
  {
   double MyVal1=10,
          MyVal2=20,
          MyVal3=30;
   switch(number)
     {
      case value1: Print(MyVal1); break; 
      case value2: Print(MyVal2); break;
      case value3: Print(MyVal3); break;
     }

  }
 

I try to explain: at start of EA a number is input eg 1,2,3 into extern int number , then during the execution of the EA a variable is called, eg value1,value2,value3. eg. If the input was '3' , then value3 would be called.

maybe . . .

 extern int number= 3;       // user input 1/2/3 . . etc

 . . .

if value[number ]  == 0; . . . 

 . .  

this would then be effectively :  if value3  ==0; . . . 

hope this makes sense :)

 

Yep, that is what my example above should help you with.

I used an enumeration because it is cleaner for the end user and a switch statement is better for a large number of options, but you'd get exactly the same result using int and 'if' statements:

extern int number = 1;

void OnTick()
  {
   double MyVal1=10,
          MyVal2=20,
          MyVal3=30,
          value =27;
   if(number==1)      { if(MyVal1==value) {} } 
   else if(number==2) { if(MyVal2==value) {} }
   else if(number==3) { if(MyVal3==value) {} }
  }
 

Alternatively, you can use the array like GumRai mentioned:

extern int number = 1;

void OnTick()
  {
   double MyVal0=10,
          MyVal1=20,
          MyVal2=30;

   double Values[3];
   Values[0]=MyVal0;
   Values[1]=MyVal1;
   Values[2]=MyVal2;

   if(Values[number]==27)
      {
 

yea , this is what I been looking for :)

thank you guys so very much

Reason: