Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1323

 
is it possible to print EMPTY_VALUE as "EMPTY_VALUE" instead of the value 1797......?
 
Fast235:
is it possible to print EMPTY_VALUE as "EMPTY_VALUE" instead of 1797......?

more info... code

"EMPTY_VALUE" cannot be 1797......

 
MakarFX:
more... code
while(CopyBuffer(handle,buffer_num,Start_bar,Count_bar,buffer) == Count_bar && !_StopFlag)
        {
         //--- в цикле проверяем номера буфера
         for(int ii=0; ii<Count_bar; ++ii)
            result_output +="\n"+name
                            +"["+IntegerToString(buffer_num)+"]"
                            +"["+IntegerToString(ii)+"]"
                            +"="+DoubleToString(buffer[ii],_Digits);
 
Fast235:
What exactly do you need for the print?
 
MakarFX:
What exactly do you need for the print?

Thank you,

there can only beEMPTY_VALUE in one place))

 
Fast235:

Thank you,

there can only beEMPTY_VALUE in one place))

I'm not an expert like you, but...

if( result_output>0) Print( result_output );

else

Print( "EMPTY_VALUE" ); 
 
class TestClass
{
  private:
    double cValue1;
  public:
    double Value1()
    {return cValue1;}

    void SetValue1(int param,double value)
    {
      if(param>0)cValue1=value;
    }
};

void TestFunction()
{
  TestClass test;
  test.SetValue1(1,0.5);
}

I would like to be able to use a recording instead of

test.SetValue1(1,0.5);

it would be possible to use an entry

test.Value1(1)=0.5;

I suspect that, if possible, it would be with overloading. But I lack the knowledge and imagination.

If this is possible, please advise how to implement it.

 
Yurij Kozhevnikov:

I would like to be able to use a recording instead of

it would be possible to use an entry

I suspect that, if possible, it would be with an overload. But I lack knowledge and imagination.

If it is possible, please advise how to implement it.

class TestClass
{
  private:
    double cValue1;
  public:
    double Value1()
    {return cValue1;}

    void SetValue1(int param,double value)
    {
      if(param>0)cValue1=value;
    }
    void operator=(const double value) { cValue1 = value; }
};
//+------------------------------------------------------------------+
void OnStart()
{
   TestClass t;
   t = 123.456;
   Print("Value1() = ", t.Value1());      // Value1() = 123.456
}
//+------------------------------------------------------------------+

https://www.mql5.com/ru/docs/basis/function/operationoverload

Документация по MQL5: Основы языка / Функции / Перегрузка операций
Документация по MQL5: Основы языка / Функции / Перегрузка операций
  • www.mql5.com
Перегрузка операций позволяет использовать операционную нотацию (запись в виде простых выражений) к сложным объектам - структурам и классам. Запись выражений с использованием перегруженных операций упрощает восприятие исходного кода, так как более сложная реализация сокрыта. Для примера рассмотрим широко применяемые в математике комплексные...
 

Thank you, such implementation has occurred to me, but it is not quite the same due to absence of Value1 itself. That is, the example I created is of course extremely simplified, but it is implied that this is not the main value of the class, that there can be a number of such values and that for each such a construct can be described.

Or for such an implementation, is it possible to describe only a separate class or structure in which to implement the overloading, and in this class to describe variables of the created type? But, if other variables of the class are involved in the assignment operation, then again, it does not add up.

Actually, I wanted to implement something similar to Let/Set/Get methods in vbs.

"Property Let/Set/Get" Procedures
  • www.herongyang.com
This section provides a tutorial example on how to use 'Property Let/Set/Get' procedure to define public properties.  Properties defined through public variables are simple to use. But you can not use them to update internal variables or other properties when their values are changes. A better way to define public properties is to use...
 
Fast235:
is it possible to print EMPTY_VALUE as "EMPTY_VALUE" instead of 1797......?

simply overload DoubleToString, if it returns the string "EMPTY_VALUE" otherwise call ::DoubleToString

Reason: