Internet Windows Android

The primitive type is boolean. Primitive type boolean Error boolean value in 1s

While setting up the next integration of 1C: Trade Management 11 with a site managed by 1C-Bitrix, I ran into such a problem: details with the “Boolean” type were uploaded to the site with the “String” type and with the value “Yes”. As a result, the standard requisites "New", "Special offer" and "Top of sales" are no longer displayed.

Unfortunately, I did not find another option on how to fix the upload to the site in 1C:UT. Improvements are minimal.

1. All values ​​of property details except Number, Date and Directory are unloaded as the universal type String. Let's make Boolean unloaded not as a string, but as a Directory, for this we find in the General configuration module "SiteExchange" the procedure UnloadBasicRequisitesPropertiesForClassifier(). Add two lines to the condition:

2. Now you need to unload the possible values. In our case, it will be only one: "Yes" with the identifier "YES". Let's add an additional condition just below in the same procedure:

3. When unloading an item property, it is necessary that if the Boolean value is true, "YES" is unloaded. To do this, we find the UnloadProperties of Nomenclature() procedure in the same module and add a couple of lines to it:

4. Now you can save the changes and start data exchange with the site. Just in case, let's go to the menu "Content - Properties of infoblocks - Catalogs - Product catalog" and check the settings of the Properties of elements with the Boolean type. Their appearance should be set as "Checkboxes":

Now "New", "Special Offer" and "Top of Sales" are correctly transferred from 1C and displayed as flags in the product card:

Many who are just starting to learn programming are faced with a new primitive type for the first time. boolean. It is also called differently boolean type. This type is named after the English mathematician George Boole, who studied mathematical logic.

Before starting to study this primitive type, let's learn in general what boolean or logical expressions are.

Boolean expressions are something like a question, to which there must be an unambiguous answer, either yes or no.

5 < 7 — Да;

5 = 8 - No;

4 > 9 - No.

There may also be more difficult questions:

Button pressed - yes;

Button pressed - no;

Boolean expressions are used in all conditional jumps:

If< Булево выражение1>then

//operators

ElseIf< BooleanExpression2> then

//operators

EndIf;

In the 1C programming language, a variable with a Boolean primitive type can be set explicitly:

A = true;

B = False;

Where True and False are the only values ​​that the Boolean primitive type can take.

True means that some statement is true (the answer is yes).

False - means that some statement, on the contrary, does not correspond to reality (Answer - No).

Also, variables with type boolean can be set using any logical expression.
For instance:

A = 5< 7 ;

B \u003d 6\u003e 9;

In this case, variable A will have the value True, and type B will have the value false;

In the 1C programming language, various operations can be performed on variables of the Boolean type.

For instance:

A = 5< 7 ;

B \u003d 6\u003e 9;

C = A AND B;

C = A OR B;

D = Not A;

There are three of them - AND, OR and NOT.

The following tables will help you understand the functionality of these operations.

Operation NOT

A B
True Lie
Lie True

Operation AND

C = A AND B A B
True True True
Lie Lie True
Lie True Lie
Lie Lie Lie

OR operation

C = A OR B A B
True True True
True Lie True
True True Lie
Lie Lie Lie

Is it possible to perform these operations in a row?

Yes, you can, these operations will be performed from left to right. And have the following level of precedence:

First: operations in parentheses are performed first

Second: Operation NOT

Third: Operation AND

Fourth: OR operation.

To avoid confusion in operations, I advise you to use parentheses wherever possible.

For instance:

A = false;

B = true;

C = false;

D = A and C or B;

In this case, the operation will work first AND between A and C.

See table A - Lie, WITH - Lie, result A AND C will Lie.

The next step is to perform the operation OR between Lies(The result of the previous operation) and the value of B, which True.

The result will be True.

And if we need the operation to go through first OR between C and B, and then only the operation AND between A and what happened, then you need to use brackets for this.

A = false;

B = true;

C = false;

D \u003d A and (C or B);

The result will be diametrically opposite. Why? Now let's figure it out. Thanks to the brackets, the operation between C and B is first performed, because WITH - Lie, and B - True, the result will be True. Then between the value of A (which Lie) and value True(the result of the previous operation) the operation is performed AND. The result will be Lie.

Many novice programmers do not fully understand the principles of interaction between Boolean variables. Only practice can help with this. And practice with Boolean variables is enough in my problem book for the book

Learn the basics of configuring in 1C and learn to program in "1C: Enterprise" with the help of my books: and "Fundamentals of Development in 1C: Taxi"

Learn programming in 1C in a place from my book "Program in 1C in 11 steps"

  1. The book is written in clear and simple language - for a beginner.
  2. Learn to understand 1C architecture;
  3. You will begin to write code in 1C language;
  4. Master the basic techniques of programming;
  5. Consolidate the acquired knowledge with the help of a task book;

An excellent guide to developing in a managed 1C application, both for beginner developers and experienced programmers.

  1. Very accessible and understandable language
  2. The book is sent by e-mail in PDF format. Can be opened on any device!
  3. Understand the ideology of a managed 1C application
  4. Learn how to develop a managed application;
  5. Learn to develop managed forms 1C;
  6. You will be able to work with the basic and necessary elements of managed forms
  7. Programming under a managed application will become clear

Promo code for a 15% discount - 48PVXHeYu


If this lesson helped you solve any problem, liked it or was useful, then you can support my project by transferring any amount:

can be paid manually:

Yandex.Money — 410012882996301
Web Money - R955262494655

Join my groups.

As a rule, the study of any programming language begins with an example of writing the first simple program (“Hello world!”). This is done in order to visually show the work with basic syntactic constructions. We will not make an exception to this common way of presenting material when learning a new development environment, and therefore our first article should be considered in the same vein. In it, we will analyze in detail the answers to the following questions regarding programming on the 1C:Enterprise 8 platform:

  • Where and with what help to write program code in the built-in 1C language?
  • What are program modules, what are the rules for working with them?
  • What is a variable, how to work with it, how and where to declare it?
  • What are the comparison, assignment, and conditional operators and how do you use them?
  • Boolean operations - what are they and how to work with them?
  • Why loops are needed and how to use them?

The article will be useful to all those who are not yet familiar with development on the 1C:Enterprise 8 platform, but want to learn how to program in 1C.

Applicability

The material is relevant for the platform "1C:Enterprise 8" editions 8.2. and 8.3.

Variables and Operators

In this article, we begin to study the built-in language 1C:Enterprise 8. The executable code is contained in program modules.

There are a fairly large number of modules that are designed to handle various events.

So, the user login is processed in one module, and the processing of the user clicking on a certain button is handled in a completely different one.

Thus, each module describes the behavior of the configuration at a certain point. The module contains, first of all, a variable declaration section. Those. we can declare some variables in a module.

In the future, they can be used in the procedures and functions of this module. If a variable is defined with the Export keyword, then it will be available outside of this module. Variable declaration line example:

Rem Warehouse, Division, Storekeeper Export;

After the declaration of variables, there is a section of procedures and functions.

Behind them is the section of the main program, which will be executed at the time of accessing this module.

For example, in the main program section, you can initialize variables, i.e. give them some initial values:

State=1;
NewExpression=2;
result=3;

A module can be thought of as a combination of different operators that perform different actions we need.

The operator separator is the character ";" (semicolon). This sign is a sign of the end of the operator. Those. operator can be written like this:

Result=100x200
+400
-600;

It doesn't matter how many lines the statement is on.

Of course, it is often more convenient and clearer to place the operator on one line, but sometimes the operators are quite long (the number of lines can reasonably reach several tens).

A semicolon can be omitted in the final statement of a given construction, for example, a procedure. Those. the following code will work:

Procedure CalculateValue()

InitialValue = 100;
IntermediateValue = InitialValue / 5;
FinalValue = InitialValue+IntermediateValue

EndProcedure

However, it is better to use a semicolon in the final statement. It is possible that over time the construction will be continued, and the final operator will no longer be final. We will have to specifically monitor this situation.

Variables are designed to hold some value of any data type. They are used for intermediate storage of information for processing.

In almost any software module that performs some action, there are various variables. Variable typing by values ​​in Platform 1C:Enterprise 8 is soft.

For example, a variable can contain a value of one data type, and a few lines later, another type:

Created = false;
Created = true;
Created =100;

In the first two statements, the value of the variables is boolean, and in the third it is changed to a numeric value. Those. typing depends on the value that is assigned to this variable.
Variables can be declared in two ways:

  • implicit method (the mention on the left side of the assignment operator describes this variable, there is no preliminary description of the variable with the word Variable, i.e. there is no special section of the declaration of variables);
  • explicit declaration of variables (Variable ControlData;). An explicit declaration of variables is used, for example, if the subsequent transfer of this variable to a function is expected.

For the names of variables, the classic description of the identifier is used. The identifier consists of letters, numbers, and underscores. An identifier must begin with either a letter or an underscore.

In this case, the name of the variable should reflect the meaning of this variable. Single-letter variable names (such as A, B, C) are bad examples. They do not reflect the essence of the variables.

Examples of correct variable names: Counter (incrementing variable for the loop), Contractor. If the variable name contains several words, then each new word, for clarity, should begin with a capital letter.

Reserved words, such as Procedure, Function, Loop, EndCycle, etc., cannot be used in variable names. (these constructs are highlighted in red in the program module).

Reserved words are built-in language operators and there are quite a few of them. All of them are presented in Syntax Assistant.

It should be noted that data types are not reserved words (for example, Array, Boolean, True, False). The system will perceive such variable names correctly.

For writing program code, case does not matter. For example, the word Procedure can be written with both capital and small letters. Moreover, uppercase and lowercase letters can be interleaved within a word.

It doesn't matter to the Platform. However, according to the rules of good manners, the beginning of a word must be written with a capital letter, all other letters in small letters.

About the language. You can use both Russian and English, and a combination of two languages. If it is convenient for someone, you can safely use English to write program code, as well as combine Russian and English. It doesn't matter to the platform.

Many names in English are quite difficult to remember. When using a combination of two languages, the readability of the program code deteriorates.

Boolean operations

Comparison operators very often use Boolean logic that returns True or False.

For example, in a conditional operator, you can compare: If Event = Sale Then the algorithm will go along one branch (ie, if the value is True), according to the False condition, another branch of the algorithm is executed.

Conditions can be quite complex, they can be combined, using the following operators: AND, OR, and NOT. So, for the AND operator:

Truth AND Truth = True;
True AND False = False;
False AND True = False;
False AND False = False.

For the OR operator, it is enough that one of the operands is equal to True, then the value of the combination will be True. The value is False only if both operands are False.

The NOT operator simply inverts the current value (False to True, True to False).

Using a combination of these operators, you can build quite complex conditions. When composing complex conditional statements, take precedence into account.

The NOT operator has the highest precedence, followed by the AND operator, followed by the OR operator. Anything enclosed in parentheses has the highest precedence and is executed first.

For example, let's set priorities (execution sequence) for operations in the above expression:

NOT(Condition1 OR Condition2) AND Condition3 OR Condition4
1.Result1 = (Condition1 OR Condition2);
2. Result2 = NOT Result1;
3. Result3 = Result2 AND Condition1;
4. Result = Result3 OR Condition4;

There is a conversion rule:

NOT (Condition1 OR Condition2) = NOT Condition1 AND NOT Condition2.

However, one should not always strive to simplify the expression, since often, logically, the expanded expression is easier to read.

assignment operator

The assignment operator should not be confused with equality, even though they have the same spelling.

The principle of the assignment operator is such that the left value (the variable on the left side) is assigned the value that is to the right of the equal sign. Let's take an example:

Variable1 = Variable2 = Variable3;

Variable1 is assigned the value of equality from Boolean logic, i.e. True if Variable2 = Variable3, or False otherwise.

When testing for the position of a novice programmer, the task is often used: to swap the values ​​of two variables in places.

This problem is solved using the assignment operator and has two solutions.

Solution #1 using temporary variable:
TempVar = Variable1;
Variable1 = Variable2;
Variable2 = TempVariable;

Solution #2:
Variable1 = Variable1 + Variable2;
Variable2 = Variable1 – Variable2;
Variable1 = Variable1 – Variable2;

Conditional operator

There is such an operator If, after which it is necessary to describe some condition (the condition itself can be quite large). The condition is followed by the word Then and the statements to be executed.

This may be followed by the keyword Else and a series of other statements. If there are several different conditions, you can use a series of keywords ElseIf(see example below). The whole structure must be completed with the keyword EndIf followed by a semicolon.

In addition to the simple and multiple conditions, there is an abbreviated form of the conditional operator: ?(Condition, Expression1, Expression2);

If the condition is true, then the Expression1, otherwise - Expression2. Code example: ExpensiveItem = ?(Item.Price>100000, True, False);

In practice, instead of comparison records with the value True (Lie) type:

If Variable = True Then
and
If Variable = False Then

the equivalent notation is actually used:

If Variable Then
and
If NOT Variable Then

Cyclic Operators

For any kind of cycle, an explicit indication of the end of this cycle is required using the keyword EndCycle. There are several types of cycles.

Cycle by counter- a cycle with a fixed number of repetitions. The condition for exiting the loop is that the limit value has been exceeded. An example of using to calculate the value of A!

A = 5;
Factorial = 1;
For Counter = 1 By A Loop
Factorial = Factorial * Counter;
EndCycle;

Loop by condition– is executed while the condition of this cycle is true. Example:

RemainderSum = 1000;
Additional Item Price = 243;
Quantity = 0;
While RemainingAmount>0 Cycle
Quantity = Quantity+1;
Remaining Amount = Remaining Amount - Quantity * Price of Additional Goods;
ExtraItem Price = ExtraItem Price * 0.8;
EndCycle
Quantity = Quantity-1;

This loop calculates how many units of a product can be bought for a given amount (1000 rubles) if, after purchasing each unit of a product, its previous price is multiplied by a factor of 0.8. The initial price of the goods is 243 rubles.

An example of a mistake when using this type of loop by beginners is an eternal loop, when the loop condition is initially true, but within the loop itself it does not change in any way.

Loop through collections (another name is For each).

The Platform has a fairly large number of collections (these are containers that contain elements of a certain type).

You can iterate over the elements of a collection using a special kind of loop.

For example, there is an array of numbers, you need to calculate the sum of all elements of the array:

Sum = 0;
For Each Element From Array Loop
Sum=Sum+Item;
EndCycle;

There are special operators for loops: Continue and abort.

If at some point in the loop the execution of further statements of this loop becomes meaningless, then the operator is used to return to the beginning of the loop and organize its next loop. Continue.

Operator abort allows the loop to end even if the loop condition is true.

This concludes our first acquaintance with the development in the internal language of 1C.

What about Hello World? We haven't written it yet, have we? Yes, but nothing prevents you from doing it yourself, because. knowledge is already enough. Well, if that doesn't work, you can look here.

Hello, dear readers of the blog site! Last time we paid attention to the built-in language 1C: Enterprise 8. Today we will continue and talk about two data types - Boolean and Date, and also consider how to work with them. So, let's begin!

Concerning data type boolean, then everything is quite simple here. There are two meanings True and Lie, which can be obtained in various ways. For example, you can use comparison operators:

  • 101 > 1001 equals Lie
  • 101 Truth
  • ‘20000101’= ‘20000102’ equals Lie
  • ‘Open’ ‘Open’ is equal to True

As you can see, you can use various operations for comparing numbers, strings, dates. As a result, some Boolean value will be obtained, which is often used in conditional statements and loop statements.

Now consider primitive data type Date. To describe a data type date usually two methods are used. First, the use of a literal. Let's declare a variable called "CurrentDate". For example, it will be equal to October 2, 2014. In this case, the date format is year/month/day.

CurrentDate = "20141002"; // 02.10.2014

If there is a need, then we can specify the time, because in the 1C: Enterprise 8 system, any date contains inside itself both the date and time. Therefore, if necessary, you can specify, for example, such a time: 15 hours 5 minutes and 50 seconds. Get year/month/day/hour/minute/second.

CurrentDate = '20141002150550'; // 02.10.2014 15:05:50

If you do not specify the time, then by default it will be zero, and the date can be described like this: '20141002'.
For clarity, any delimiter can be used, such as periods "." So the date might look like this: '2014.10.02'. This was the first way to describe a date. Note that single quotes are used, i.e. a literal that cannot be broken. It is written in single quotes.

The second way to determine the date is to use the global context function Date(). In this case, we pass the same thing as a parameter to this function: year/month/day. Parameters here must be specified separated by commas.

CurrentDate = Date(2014, 10, 02); // 02.10.2014 00:00:00

You can also specify the time.

CurrentDate = Date(2014, 10, 02, 15, 05, 50); // 02.10.2014 15:05:50

If the time is not specified, then it will be equal to the beginning of the day. You can also write the following call to this function:

CurrentDate = Date("20141002150550"); // 02.10.2014 15:05:50

It uses one parameter with a string that must contain a date in the format: year/month/day/hour/minute/second.

In order to describe an empty date in the 1C: Enterprise 8 system, you need to do the following:

EmptyDate = ""; // 01.01.0001 00:00:00

Or using a literal description:

EmptyDate = "00010101"; // 01.01.0001 00:00:00

Another way, using the global context function we already know:

Empty date = Date(1, 1, 1); // 01.01.0001 00:00:00

Using these methods will return the same result and the date will be considered empty. Function convenience date is that we can pass here not specific values, but variables. Sometimes you need to get the date by collecting different variables. The function is very helpful for this. date.

And I also want to note that the addition operation is applicable for the date. If you add the number ten to the date:

CurrentDate = Date(2014, 10, 02, 15, 05, 50); // 02.10.2014 15:05:50 CurrentDate = CurrentDate + 10;

As a result, we will get the date ten seconds more:

02.10.2014 15:06:00

So, the addition operation adds a certain number of seconds to the specified date. This is a difference from the version of the 1C:Enterprise 7.7 system, where when adding dates, the number of days, not seconds, was added.