A
A
Alexander2019-06-24 15:49:44
1C
Alexander, 2019-06-24 15:49:44

What is wrong in the code (1C)?

Hello! I’ll immediately clarify this point - I’m new to programming, and to 1C too. "Why 1C?" - you ask? "Start with a python!" others will say. Prospects appeared in 1C and I eagerly study everything connected with it, on the second day I climbed directly into a more flexible automation of calculations. I want to make an automatic calculation of the employee's length of service in the format (dd.MM.yyyy). According to the past lesson on YouTube, I decided to write a simple code, how much joy it was when the module check did not give errors, but the plan was never fulfilled. Can anyone tell me where is the error in the code?
5d10c6cb4b4ef320126064.png5d10c6d10a6c7987007774.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Kinash, 2019-06-24
@razor_ru

What is wrong?
1) EmptyString() - a function for checking a string variable for the presence of significant characters (spaces, tabs and other separators are ignored) - obviously not intended for checking the total length of service, which will be converted to the string "0" and the function will always give a False result. If the final seniority is not the days of the final seniority, but the date of dismissal (with the names you still have to work and work - you confuse yourself), then the date is also converted to a string literal, which will give a similar False. Because the content inside the condition will never be executed!
2) Calls of the type "Object." refer to the details of your document, and not to the details of the rows of the tabular part! You need to first find out the value of the current row of the tabular section (under the cursor) and then work with this row.
3) What you tried to assign in binary format is not clear, but obviously not the topic.
4) Suppose that you wanted to reset the date with your ones and zeros. Then, according to your formula, you add to an empty date the sum of the number of seconds from the date of admission from the number of seconds from the date of dismissal - this will be somewhere around 4036.
UPD. Added after correspondence in the comments
1) What should be in the Total? In theory, the number of months! The "String" type is useless here - the quantity is always the "Number" type.
2) On the field of the tabular section, you need to add an event handler OnChange with approximately the following content:

&НаКлиенте
Процедура СтажРаботыПриИзменении(Элемент)
  
  РедактируемаяСтрока = Элементы.СтажРаботы.ТекущиеДанные;
  
  // строку могли удалить и в таблице ничего нет
  Если РедактируемаяСтрока = Неопределено Тогда
    Возврат;
  КонецЕсли; 
  
  // обязательно делаем проверку данных!
  Если РедактируемаяСтрока.ДатаПриема >= РедактируемаяСтрока.ДатаУвольнения Тогда
    РедактируемаяСтрока.Итог = 0;
    Возврат;
  КонецЕсли; 
  
  // в зависимости от требуемого значения делаем расчет
  // еще важен способ округления - к меньшему целому или к большему
  ОтработаноСекунд = РедактируемаяСтрока.ДатаУвольнения - РедактируемаяСтрока.ДатаПриема;
  ОтработаноЧасов = ОтработаноСекунд / 60;
  ОтработаноДней = ОтработаноСекунд / 86400;
  
  // если нужно значение месяцев или лет, то используем сдвиги в цикле
  ОкруглятьКБольшему = Истина;  // 1 день сверху дасть дополнительный 1 месяц или 1 год
  
  ОтработаноМесяцев = ?(ОкруглятьКБольшему, 0, -1);
  СкользящийМесяц = РедактируемаяСтрока.ДатаПриема;
  Пока СкользящийМесяц < РедактируемаяСтрока.ДатаУвольнения Цикл
    ОтработаноМесяцев = ОтработаноМесяцев + 1;
    СкользящийМесяц = ДобавитьМесяц(СкользящийМесяц, 1);
  КонецЦикла;
  
  ОтработаноЛет = ?(ОкруглятьКБольшему, 0, -1);
  СкользящийГод = РедактируемаяСтрока.ДатаПриема;
  Пока СкользящийГод < РедактируемаяСтрока.ДатаУвольнения Цикл
    ОтработаноЛет = ОтработаноЛет + 1;
    СкользящийГод = ДобавитьМесяц(СкользящийГод, 12);
  КонецЦикла;
  
  // выводим значение на форму
  РедактируемаяСтрока.Итог = ОтработаноМесяцев;
  
КонецПроцедуры

But I am not moderate in that you need seniority props. Perhaps it would be enough to have a "virtual attribute" (added to the tabular part on the form) really with the type of String, where, when opened and changed, output calculated data in the form "10 years, 4 months, 17 days".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question