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

 
ANDREY:

Thanks for the clarification.

By the way, I removed the yellow pluses and the compiler gave an error. So they play some role in this whole construction. But what.... I still don't understand. What for they are needed when string addition is performed only through the use of blue pluses. Judging by your explanations, there is nothing else in this construction ..... if I'm not mistaken.

And about string(i)... About the type conversion .... is more or less clear to me. What is not clear is that..... string is the name of a variable type. i is a counter variable denoting the index of an array element. And why isi in parentheses () ? I've been thinking so far that parentheses are a function characteristic. For example, Print( ). And different data are put inside parentheses in some functions. But what do parentheses mean or what function do parentheses perform with respect to i and this whole construct - string(i)? At first glance, it seems that before the i variable had an int type (integer), and then you changed the i variable's type from int to string (string) . But round brackets containing i do not let me think so.

Thanks for the explanation.

This is not a type conversion, but a conversion of a value in the i variable

You can often see it this way

eStr+=(string)i+": "+DoubleToString(eArray[i],4)+", ";
 
Alekseu Fedotov:

This is not a type conversion, but a transformation of the value found in the variable i

can more often be seen as


Thanks for the tip. Value conversion of the i variable. What do you mean in my code?
1. The value
of i was 0, after(string)i+ it became 1, then 2 and so on up to 30. Why do I need (string) instead of justi++?
2. The type of the i variable was int, and after (string)i+ it became string? Well, this is not value conversion, but transformation of the variable type.


And also .... Maybe you can explain me what the yellow pluses add up to. Or what are they for?

 eStr+=string(i)+": "+DoubleToString(eArray[i],4)+", ";

Thanks for the explanation.

 
ANDREY:

Thanks for the tip. Convert the value of variable i. What is meant in my code?
1. The value
of i was 0, after(string)i+ it became 1, then 2 and so on up to 30. Why do I need (string) instead of justi++?
2. The type of the i variable was int, and after (string)i+ it became string? Well, this is not value conversion, but conversion of the variable type.


And also .... Maybe you can explain me what the yellow pluses add up to. Or what are they for?

Thanks for the explanation.

Type conversion or explicit type conversion are equal. The documentation uses both expressions. You correctly noted Alexey's caveat, it is type conversion that...

Further: We have several strings

  1. i of type int which was explicitly converted to type string (let it be 0)
  2. ": "
  3. eArray[i] casted to string type via DoubleToString function (let it be 1.6251)
  4. ", "

The value of i is incremented in the loop at each iteration and gets into this string from there...

Note that pluses are put between these strings. These pluses add up these lines into one line. The result is the string "0: 1.6251," and then this string is appended to the string in the eStr variable by operator +=


 
ANDREY:

Thanks for the tip. Convert the value of variable i. What is meant in my code?
1. The value
of i was 0, after(string)i+ it became 1, then 2 and so on up to 30. Why do I need (string) instead of justi++?
2. The type of the i variable was int, and after (string)i+ it became string? Well, this is not value conversion, but conversion of the variable type.


And also .... Maybe you can explain me what the yellow pluses add up to. Or what are they for?

Thanks for the explanation.

With yellow pluses you form a string (text) which you output withPrint();

You can do the same with StringConcatenate()

eStr+=StringConcatenate((string)i,": ",DoubleToString(eArray[i],4),", ");
 
Alekseu Fedotov:

You use the yellow plus sign to form a string (text), which you output withPrint();

You can do the same with StringConcatenate()

I do not advise to use this function as it works quite differently in MQL5 than in MQL4. Consequently, it may be hard to understand it when you switch to MQL5.


But maybe I'm wrong...

mql4

string  StringConcatenate( 
   void argument1,         // первый параметр любого простого типа  
   void argument2,         // второй параметр любого простого типа 
   ...                     // следующий параметр любого простого типа 
   );

mql5

int  StringConcatenate( 
   string&  string_var,   // строка для формирования 
   void argument1         // первый параметр любого простого типа  
   void argument2         // второй параметр любого простого типа 
   ...                    // следующий параметр любого простого типа 
   );

As you can see, in mql5, it is very similar to simple addition of strings.

 eStr+=string(i)+": "+DoubleToString(eArray[i],4)+", ";
 StringConcatenate(eStr, i, ": ", eArray[i], ", ");
And type conversion takes place in this function without any additional worries.
 
Alexey Viktorov:

I do not recommend to use this function because it works differently in MQL5 than in MQL4. Consequently, it may be hard to understand when you switch to MQL5

Thanks for the valuable information

 
Alekseu Fedotov:

You use the yellow plus sign to form a string (text), which you output withPrint();

You can do the same with StringConcatenate()

Thanks for the new information for me

 
ANDREY:

Thank you for the valuable information

I have added to my hastily written message.

It's already clear to everyone how grateful you are to everyone who explains something to you. Don't stretch the topic with separate messages...

 
Alexey Viktorov:

Next: We have several strings

  1. i of int type which is explicitly of string type (let it be 0)
  2. ": "
  3. eArray[i] converted to string typeviaDoubleToString (let it be 1.6251)
  4. ", "




Why can't 1.6251 be cast to the string type explicitly like i? It's shorter and saves computational resources..... it seems to me.

Thanks for the explanation

 
Alexey Viktorov:

I have added to my post hastily written.

And it's already clear to everyone how grateful you are to everyone who explains something to you. Don't stretch the topic with separate messages...

Okay. Then a thank you for each of your replies will be implied by default( will be stored in a variable :):):) ).... if you don't mind.