[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 559

 
peco:

I'm sorry, I can't find... can you tell me please.

HOW TO MOVE ALL ELEMENTS OF A ONE-DIMENSIONAL ARRAY BY 1 INDEX?

Is there an operation or does it need to be done in a loop?


https://www.mql5.com/ru/forum/131859/page8#434278
 
Chiripaha:

Not really...

I wanted to do something like a menu. Just like in bool variable either false or true.
So that the user can click only on clearly defined values of the parameter. So that he "mistakenly" does not enter unnecessary ones, because in this case, the Expert Advisor will not work correctly.

The user is even myself. As it is possible to forget what parameters should be there for a particular variable.

MQL4 does not have such a possibility (but MQL5 does). You can check this parameter in initialization and if it does not correspond to a certain value, then signal an error. Then at the very beginning of the start it should be checked. I did so in my EA, for example:

extern int  val=5;
       bool val_error=false;
// -----
init()
{  ...
   if (val!=5  || val!=10 || val!=20 || val!=40 ||
       val!=60 || // и т.д.)
      {   val_error=true;
          Alert("Неправильный val!");
      }
   ...
}
// -----
start()
{  if (val_error=true) return;
   ...
}
 

Hi all. I'm trying to write a function that writes a file to a directory specified by the user (working outside the sandbox).

I wrote code using"ZI_File_Functions_Full_Lib" libraryhttps://www.mql5.com/ru/code/8577

The function"PathFunctions.dll."https://www.mql5.com/ru/code/10873 is not suitable as it works with Vista, I have Windows 7.

All unnecessary things removed as reading is not needed, just take directory and there create file with value which is initially known, that's all.

Questions:

1. I can't figure out where is the value we are writing to the file?

2. I cannot locate where a mistake is written?

Thanks in advance.

//===============================================================================================================================================================
//     Импортируемые функции.
//===============================================================================================================================================================

#import "ntdll.dll"
int RtlGetLastWin32Error();
int RtlSetLastWin32Error (int dwErrCode);
#import
#include <WinKernel32.mqh>                                      // Заголовочный файл библиотеки "kernel32.dll" функций API Windows XP.

//===============================================================================================================================================================
// Объявленные константы.
//===============================================================================================================================================================

#define FILE_FULL_CREATE    0                                   // Создать или переписать файл.

//===============================================================================================================================================================
//    Функция открывает или создаёт файл.
//    Функция открывает/создает файл для ввода и/или вывода. Если при открытии для записи файла нет, то он будет создан. Для создания директории
//    используется функция "CreateDirectory()". Функция возвращает: handle - файловый описатель, если функция выполнилась без ошибки;
//                                                               -1     - возникла системная ошибка;
//                                                               -2     - ошибка при перемещении файлового указателя в конец файла;
//                                                               -3     - указан недопустимый способ открытия файла.
//===============================================================================================================================================================
int start(){
   int FileOpenFull (string PathName="D:\files\DATA.csv",      // Имя файла с абсолютным путём.
                     int    ModeCWR=0)                         // Способ открытия файла: 0 - FILE_FULL_CREATE    Открытие файла для записи. Если файл существует, то содержимое файла будет
                                                               //                                                уничтожено. Если файл с таким именем не существует, то будет создан новый.
    {
     int Error;                                                // Номер последней ошибки.
     int Handle;                                               // Файловый описатель.
//===============================================================================================================================================================
  RtlSetLastWin32Error(0);                                                                                              // Обнуляем ошибку.
  if (ModeCWR != FILE_FULL_READ)                                                                                        // Если функция вызвана не для чтения, проверяем на наличие файла.
   {                                                                                                                    // Проверяем на наличие файла. Читаем файл.
    Handle = CreateFileA (PathName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    if (RtlGetLastWin32Error() == 2 && Handle == -1) ModeCWR = FILE_FULL_CREATE;                                        // Файла нет. Создаём файл.
    else
     {
      if (!CloseHandle (Handle))
       {
        Error = RtlGetLastWin32Error();
        Print ("Ошибка в функции \"FileOpenFull()\". Файл с путём \"", PathName, "\" не закрыт при проверки на наличие. Последняя ошибка: \"", Error, "\". ", StringError (Error));
        return (-1);
       }
     }
    RtlSetLastWin32Error(0);                                                                                            // Обнуляем ошибку.
   }
   
//===============================================================================================================================================================
//     Переключатель по способам открытия файла.
//===============================================================================================================================================================
  
  switch (ModeCWR)
   {                                                                                                                    // Создаём файл.
    case FILE_FULL_CREATE:
     {
      Handle = CreateFileA (PathName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
      if (Handle == -1)
       {
        Error = RtlGetLastWin32Error();
        Print ("Ошибка в функции \"FileOpenFull()\". Файл с путём \"", PathName, "\" не открыт. Последняя ошибка: \"", Error, "\". ", StringError (Error));
       }
      return (Handle);
     }
    
//===============================================================================================================================================================
//     Функция закрытия файла.
//     Функция закрывает ранее открытый файл. Если файл закрыт успешно, функция возвращает TRUE, иначе возвращает FALSE.
//===============================================================================================================================================================

   bool FileCloseFull (int Handle)                                                                                   // Файловый описатель, возвращаемый функцией "FileOpenFull()".
    {
     int Error;                                                                                                      // Номер последней ошибки.
     //----
     RtlSetLastWin32Error (0);
     if (!CloseHandle (Handle))
      {
       Error = RtlGetLastWin32Error();
       Print ("Ошибка в функции \"FileCloseFull()\". Последняя ошибка: \"", Error, "\". ", StringError (Error));
       return (false);
      }
     else return (true);
    }

//===============================================================================================================================================================
//    Функция возвращает код системной ошибки.
//===============================================================================================================================================================

   int SystemError()
    {
     return (RtlGetLastWin32Error());
    }
 
//===============================================================================================================================================================
//    Функция возвращает строковое описание кода системной ошибки.
//===============================================================================================================================================================

   string StringError (int ErrorCode)                                                     // Код системной ошибки.
    {
     int    i;
     string String = "";
     //----
     int    Buffer[128];
     //----
     ArrayInitialize (Buffer, 0);
     FormatMessageA (0x1000, 0, ErrorCode, 0, Buffer, ArraySize (Buffer), 0);
     //----
     for (i = 0; i < ArraySize (Buffer); i++)
      {
       String = String + CharToStr (Buffer[i]       & 0xFF)
                       + CharToStr (Buffer[i] >>  8 & 0xFF)
                       + CharToStr (Buffer[i] >> 16 & 0xFF)
                       + CharToStr (Buffer[i] >> 24 & 0xFF);
      }
     return (StringTrimRight (String));
    }
//===============================================================================================================================================================
//    Конец
//===============================================================================================================================================================
}
 
merkulov.artem:

Hi all. I'm trying to write a function that writes a file to a directory specified by the user (working outside the sandbox).

I wrote code using"ZI_File_Functions_Full_Lib" libraryhttps://www.mql5.com/ru/code/8577

The function"PathFunctions.dll."https://www.mql5.com/ru/code/10873is not suitable as it works with Vista, I have Windows 7.

All unnecessary things removed as reading is not needed, just take directory and there create file with value which is initially known, that's all.

Questions:

1. I can't figure out where is the value we are writing to the file?

2. I cannot locate where a mistake is written?

Thanks in advance.

Artyom!!! Where is it written that it does not work with Windows 7? Why are you reading so inattentively? I'm not surprised that it doesn't work for you.



I looked at your code and realized that you do not know how to program. Take the example from the help first. Run it. See how it works. Then go on to more complicated things.

A file is first created or opened. Then write or read it. Then close it. You just copied the function declarations into the start. You have torn a piece of code out of a universal function. Now it just hangs there. It has nothing to do with anything. What's that for? It won't work.

 
Good afternoon, could you please tell me how to close the strategy tester, what do I have to press?
 
angelina8:
Good afternoon, could you please tell me how to close the strategy tester, what do I have to press?

 
You can either press Ctrl+R or the button in the mt4 menu, which is circled in red in the illustration above.
 
Which document do I have to upload to my personal account?
 
angelina8:
Which document do I have to upload to my personal account?

What for?
 
to withdraw funds
Reason: