Enum as Input in string

 

Hey all,

I would like to ask if anyone of you know how to get enum as an input variable in string. I tried this #define method and StringFind() function but it produce some error and warning as per this picture. Here I also attach the code I tried to write:

#define Nonfarm_Payrolls "Nonfarm Payrolls"
#define CPI_y_y "CPI y/y"
#define BoE_Interest_Rate_Decision "BoE Interest Rate Decision"
#define Fed_Interest_Rate_Decision "Fed Interest Rate Decision"
#define ECB_Interest_Rate_Decision "ECB Interest Rate Decision"
#define BoC_Interest_Rate_Decision "BoC Interest Rate Decision"
#define RBNZ_Interest_Rate_Decision "RBNZ Interest Rate Decision"
#define BoJ_Interest_Rate_Decision "BoJ Interest Rate Decision"
#define Nationwide_HPI_y_y "Nationwide HPI y/y"

enum EVENT_NAME{
      Nonfarm_Payrolls,
      CPI_y_y,
      BoE_Interest_Rate_Decision,
      Fed_Interest_Rate_Decision,
      ECB_Interest_Rate_Decision,
      BoC_Interest_Rate_Decision,
      RBNZ_Interest_Rate_Decision,
      BoJ_Interest_Rate_Decision,
      Nationwide_HPI_y_y
};
input EVENT_NAME eventName = Nationwide_HPI_y_y;

 if (StringFind(eventName,event.name) >= 0){
        do X


 

 
#define Nonfarm_Payrolls "Nonfarm Payrolls"
#define CPI_y_y "CPI y/y"
#define BoE_Interest_Rate_Decision "BoE Interest Rate Decision"
#define Fed_Interest_Rate_Decision "Fed Interest Rate Decision"
#define ECB_Interest_Rate_Decision "ECB Interest Rate Decision"
#define BoC_Interest_Rate_Decision "BoC Interest Rate Decision"
#define RBNZ_Interest_Rate_Decision "RBNZ Interest Rate Decision"
#define BoJ_Interest_Rate_Decision "BoJ Interest Rate Decision"
#define Nationwide_HPI_y_y "Nationwide HPI y/y"

string EVENT_NAMES = 
      Nonfarm_Payrolls + "," +
      CPI_y_y + "," +
      BoE_Interest_Rate_Decision + "," +
      Fed_Interest_Rate_Decision + "," +
      ECB_Interest_Rate_Decision + "," +
      BoC_Interest_Rate_Decision + "," +
      RBNZ_Interest_Rate_Decision + "," +
      BoJ_Interest_Rate_Decision + "," +
      Nationwide_HPI_y_y;

void OnTick(void)
  {
   StringFind(EVENT_NAMES, event.name);
  }
 
Yashar Seyyedin #:
Thank you for your response. However, I tried it and still didnt work. I tried to make a string function instead, and it  works now
string eventString(){

   if(eventName == Nonfarm_Payrolls){return "Nonfarm Payrolls";}
   else if(eventName == CPI_y_y){return "CPI y/y";}
   else if(eventName == BoE_Interest_Rate_Decision){return "BoE Interest Rate Decision";}
   else if(eventName == Fed_Interest_Rate_Decision){return "Fed Interest Rate Decision";}
   else if(eventName == ECB_Interest_Rate_Decision){return "ECB Interest Rate Decision";}
   else if(eventName == BoC_Interest_Rate_Decision){return "BoC Interest Rate Decision";}
   else if(eventName == RBNZ_Interest_Rate_Decision){return "RBNZ Interest Rate Decision";}
   else if(eventName == BoJ_Interest_Rate_Decision){return "BoJ Interest Rate Decision";}
   else if(eventName == Retail_Sales_m_m){return "Retail Sales m/m";}
   
   else return "Choose One News";
}
 
donnacitra98 #:
Thank you for your response. However, I tried it and still didnt work. I tried to make a string function instead, and it  works now


string EventToString(EVENT_NAME eventname){
   string eventstring = EnumToString(eventName);
   StringReplace(eventstring,"_"," ");
//---
  return(eventstring);
}
 
Alain Verleyen #:


Thank you so much. It is so efficient.