How to access input box string value ?

 

I declared the control Inputbox :

CInputBox m_ib; (As in sample https://www.mql5.com/en/articles/322)

, Placed button event that must print in alert box that inputbox value :

if(m_but.Event(id,lparam,dparam,sparam)==1) {

           Alert("Mbut event: " + m_ib.ValueString());}

, but I cannot see in my alertbox m_ib string ("MyText") what I want (Instead of "MyText" there is "0.00").

How I can succeed the right value in Mbut event?

Thank you!

Custom Graphical Controls. Part 3. Forms
Custom Graphical Controls. Part 3. Forms
  • 2011.12.20
  • Dmitry Fedoseev
  • www.mql5.com
This is the last of the three articles devoted to graphical controls. It covers the creation of the main graphical interface component - the form - and its use in combination with other controls. In addition to the form classes, CFrame, CButton, CLabel classes have been added to the control library.
 

You have to use following code (or similar) in OnChartEvent().

m_ib.Event(id,lparam,dparam,sparam);
 

There is my full code what I am trying to test:

//+------------------------------------------------------------------+
//|                                         eIncGUI_v3_Test_Form.mq5 |
//|                        Copyright 2011, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"

#include <IncGUI_v3.mqh>

enum eColorScheme{
   DefaultScheme=0,
   YellowBrownScheme=1,
   BlueScheme=2,
   GreenScheme=3,
   YellowBlackScheme=4,
   LimeBlackScheme=5,
   AquaBlackScheme=6
};

input eColorScheme ColorScheme=DefaultScheme;



class MyCForm: public CFormBase{
   public:
      // 1. Declaring the controls
       CInputBox m_ib;
       CButton m_but;
   protected:
      // 2. Declaring the variables to restore the control values  
      int m_EventsCounter;
         void MainProperties(){
            // Setting the form parameters
            m_Name         =  "Form";        // Form name. The names of all the controls should start with it.
            m_Width        =  260;           // Form width
            m_Height       =  200;           // Form height
            m_Type         =  1;             // Form type: 0 - without buttons, 1 - with "Apply" and "Cancel" buttons, 2 - with the "Close" button
            m_Caption      =  "FormCaption"; // Form caption
            m_Movable      =  true;          // Movable form (the button with a hand image is displayed in the top left corner)
            m_Resizable    =  true;          // Form minimizing/maximizing allowed (the button with a rectangle image is displayed in the top right corner)
            m_CloseButton  =  false;         // Form closing allowed (the button with a cross image is displayed in the top right corner)
         }
         void OnInitEvent(){
            m_ib.Init(m_Name+"_IB",40,2);
            m_but.Init(m_Name+"_But",50,15);
         }  
         void OnShowEvent(int aLeft,int aTop){
         m_ib.Show(frm.Left()+40,frm.Top()+100);
         m_but.Show(frm.Left()+140,frm.Top()+100);
          }
         void OnHideEvent(){
         m_ib.Hide();
         m_but.Hide();
          }
         void EventsHandler(const int id,const long& lparam,const double& dparam,const string& sparam){
           string val=m_ib.ValueString();
           if(m_but.Event(id,lparam,dparam,sparam)==1) {
           Alert("Mbut event: " + val);}
          }
         bool OnApplyEvent(){
            // 11. Checking the control values upon closing by the "Apply" button. In order to reject the closing of the form, false should be returned from this method.
            // 12. Saving the parameters.
             string val=m_ib.ValueString();
             Alert("Apply event: " + val);
             return(true);
         }
         bool OnCancelEvent(){
            // 13. Checks upon closing by the "Cancel" or "Close" buttons. In order to reject the closing of the form, false should be returned from this method.
            return(false);
         }
};

MyCForm frm;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit(){

   //ClrScheme.SetScheme(ColorScheme);
   // Main form
   frm.Init();
   frm.Show(30,30);
   return(0);
   }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason){
   frm.Hide();
   
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick(){
}
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam
                  ){
  int ev=frm.Event(id,lparam,dparam,sparam);
      switch(ev){
         case 1:
            Alert("Form "+frm.Name()+"("+frm.Caption()+"). Cancel event");
         break;
         case 2:
            Alert("Form "+frm.Name()+"("+frm.Caption()+"). Apply event");
         break;
         case 3:
            Alert("Form "+frm.Name()+"("+frm.Caption()+"). Resize event"); 
         break;
   m_ib.Event(id,lparam,dparam,sparam);       
      }

}

I added m_ib.Event(id,lparam,dparam,sparam); in OnChartEvent at end of the code, but it caused error 'm_ib' - undeclared identifier. Strange that frm (what i s also in OnChartEvent) is not undeclared identifier. Where is difference, what I did wrong?

 
I noticed that there was error in brackets. But when brackets are right, error still stays. I'm sorry.
 

Forum on trading, automated trading systems and testing trading strategies


Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.


 
SteelAce:

There is my full code what I am trying to test:


I added m_ib.Event(id,lparam,dparam,sparam); in OnChartEvent at end of the code, but it caused error 'm_ib' - undeclared identifier. Strange that frm (what i s also in OnChartEvent) is not undeclared identifier. Where is difference, what I did wrong?

Of course when I wrote "similar", it means you have to think a little where and how to place this code

Add the line in MyCForm :

         void EventsHandler(const int id,const long& lparam,const double& dparam,const string& sparam){
           m_ib.Event(id,lparam,dparam,sparam);       
           string val=m_ib.ValueString();
           if(m_but.Event(id,lparam,dparam,sparam)==1) {
           Alert("Mbut event: " + val);}
          }

or use this in OnChartEvent :

   frm.m_ib.Event(id,lparam,dparam,sparam);

frm is an instance of MyCForm declared globally. So accessible everywhere in your EA.

m_ib is a property of this object.

So you can either place this line inside your class or in OnChartEvent.

Reason: