1c find out the type of value. Through object creation

- classification of values ​​(that is, data) according to their type - strings, numbers, dates, etc. A value type is one of the basic concepts in any programming language.

Type conversion is the conversion of a value (data) from one type to another, such as from a string to a number or vice versa. A narrower concept of value formatting is conversion from any type to a string with conversion to a form that will be convenient for the user to read, including localization.

There are languages ​​with strong data typing. This means that when creating (defining) a variable, the programmer strictly specifies what type of data it can store. The same with functions, procedure parameters, etc. In 1C metadata, the type of details is strictly specified (although there is a composite type that allows you to specify several options). But in the program code in the 1C language there is no strict typing, which means that you can create a numeric variable, then equate it to a string. The function can, depending on the parameters and conditions, return a number, or a Boolean, or a string.

How to work with data types in the 1C language and how to convert 1C types?

Value 1C Undefined

Undefined is a 1C value that means there is no value. Using this 1C value, you can “zero” variables, including for implicitly calling a destructor, for example, COM objects.
Variable1 = New COMObject("Excel.Application");
Variable1 = Undefined;

A similar value is 1C NULL, which can be returned by a request when trying to obtain data from the database, if it was not possible to obtain it (more precisely, the value in the NULL field means that the field in the database is “not filled”).
Select = Query.Run().Select();
While Select.Next() Loop
If Selection.Field1 = NULL Then
Continue;
endIf;
EndCycle;

Types of 1C values

It is possible to use the following as “variables”:

  • Variables created in the program text (using the methods described above)
  • Details of the metadata object or form (created in the configurator, indicating the exact 1C type).

The props can have a composite type 1C, that is, several possible ones. Assigning the 1C value by the user in this case can be a two-step process:

  • Selecting a 1C value type from the available ones
  • Selecting the value 1C.

By default, this attribute has the value 1C Undefined. When the 1C type is selected, but the 1C value has not yet been selected, the empty value of this 1C type (0 for a number, an empty link for 1C reference types, see below). And finally then – the value 1C. From the program, values ​​are assigned directly, without intermediate selection of the 1C type.

It is possible to determine the type of 1C value in several ways:
//method 1 – comparison with known 1C types
Variable1 = 12;
If TypeValue(Variable1) = Type("Number") Then
//…
OtherwiseIf TypeValue(Variable1) = Type("DirectoryLink.DirectoryName") Then
//…
endIf;

Conversion of 1C types

The 1C value of simple 1C types can be converted using the operator - 1C type name:
//to number
ValueNumber = Number("22"); //if it is impossible to convert 1C types, an error will be raised, so it is better to use an error handler (see below)

//to the line
ValueString = String(22);
ValueString = AbbrLP(22);
ValueString = Format(22, "CHG=0");

//on date
ValueDate = Date("20120101120000"); //01.01.2012 12:00:00
ValueDate = Date(2012, 01, 01, 12, 0, 0);
ValueDate = Date(2012, 01, 01);

Conversion of 1C types - values ​​of complex 1C types

Formatting 1C values

To specify the exact format, the Format() function is used, with which it is possible to specify the required representation.
NumberString = Format(2400, "Settings")

In the “Settings” line you need to specify the required 1C format. Such settings are indicated in a special encoded form. Let's look at the most commonly used settings:

1C format of dates and numbers according to the rules of various countries
If you need to display a date or number and don’t want to bother with knowing how they should be presented according to the rules of the desired country, there is a simple setting that will allow you to do this:
L = Short Name of the Desired Country

An example of date output according to the rules of some countries:
Format(CurrentDate(), “L=ru”)
> 28.03.2012 14:21:32
Format(CurrentDate(), "L=en")
> 3/28/2012 2:21:24 PM
Format(CurrentDate(), "L=fr")
> 28/03/2012 14:22:08

Date format in 1C language
If the default setting is not enough for you and you would like to independently specify the order of the date parts and the symbols for separating them, you must use the setting:
DF = "dmg chms"

Accordingly, “dmg” is the day, month and year, and “chms” is the hours, minutes and seconds. It is possible to skip any of these parts. The order is any. The characters specified between the parts will be used as separation characters.

Date part symbol m.b. is indicated several times in a row, the type of this part of the date depends on this, for example “d” or “dd” or “dddd”.

Explanation of date parts:

  • d – day
    o small "d"
    o from 1 to 4 times
  • M – month
    o big "M"
    o from 1 to 4 times
  • g – year
    o small "g"
    o 1 or 2 or 4 times
  • h – hours
    o small “h” - 12 hour format
    o large “H” - 24-hour format
    o 1 or 2 times
  • m – minutes
    o small "m"
    o 1 or 2 times
  • s – seconds
    o small "s"
    o 1 or 2 times
  • bb – display AM/PM for 12-hour format
  • k – quarter.

An example of displaying a date indicating the rules:

Number format in 1C language
Unlike formatting a date, where everything is quite simple, formatting a number has many options. Here are those that are most often used.

The first "problem" is related to the default grouping of digits in numbers by 3 and separating the groups with a space, for example:
StrNumber = String(22300500)
> 22 300 500

This is inconvenient when a number is converted to a string not for beautiful and understandable output to the user, but for service needs. This can be influenced using the “CHG” parameter, for example:

A parameter that allows you to round a number when outputting to the required number of digits after the decimal point “NFR”:
Format(3.535353, "BDT=""2""")
> 3,54

A parameter that allows you to specify the separator character between the integer and fractional parts of “BRD”:
Format(3.535353, "BRD="".""")
> 3.535353

In some cases, it can be useful to be able to display something else instead of the number “0”: an empty string or “not filled”. This allows you to do the “CHN” parameter:
Format(0, "CHN=""""")

There are a lot of predefined value types in 1C; they can be divided into several groups.

Fast passage

Data type groups

  • simple (primitive) types
  • object types and their subordinates
  • object types from metadata (application types)
  • interface types
  • other general purpose types

Simple types

  • String (specified by the value in quotes "")
  • Number (Specified as a decimal number)
  • Date (date and time)
  • Boolean (True, False.

Object types

  • Collections of values ​​(Arrays, Structures, Value Tables and others)
  • Integration (Com, files, external objects, zip, WS)
  • General purpose

Objects from metadata (application)

  • Constants
  • Directories
  • Documentation
  • Transfers
  • Reports
  • Treatments
  • Charts of accounts
  • Tasks
  • Information registers
  • Savings registers
  • Accounting registers
  • and others…

Interface

Related to windows, forms and form elements (fields, labels, tabular data and others)

Other options for subdividing values

  • Values ​​that can be written down to the object details (in the infobase field) and those which are not allowed
  • Objects that can be visualized, and those that have virtual entity
  • Value types that, related to the configuration and its objects or working separately
  • Which can be differentiated according to user rights - cannot
  • They can quite simple transform- either auxiliary conversion required
  • Eat properties and methods- either none

Setting Value Types

The value can be set:

Directly

This_Variable = "This is a string value";

Through object creation

This_Variable = NewColor;

Through the result of a system function call

This_Variable = Date(2016,1,1);

By accessing an object property

This_Variable_Object_Color = New Color; This_Variable = This_Variable_Object_Color.Green;

Compound and simple types

Unless specifically stated, the value type is not limited.

In the case of details of metadata objects, the type of values ​​is set at the configuration stage from the types available for writing (primitive, links to objects, value storage), as well as from the type of object and context (environment, place) of execution. In this case, it is possible to limit the props to one type or several. For example, we need to write either a “string” value or a “number” value in one field.

For other objects, the type of details may remain unrestricted (of an arbitrary type), or limited through a special type " DescriptionTypes«

For example, for the simple case

Type Description = New Type Description ("Number, String");

This object is also used to limit the selection or entry of data in dialog forms

Casting values

Produced automatically when assigning an object to an attribute (property), if this attribute cannot store this value

Also, during concatenation operations, it is carried out first to the first term, when subtracting, if possible, to the second, and then to the result.

Color = New Color(255,0,0); Color2 = New Color("2"+59-Color.Red,0,0); //In this case, it will happen in stages //"2"+59 ="259" //259-255 = 4 //Color2 = New Color(4,0,0);

Such “complex” conversions must be carried out with caution.

Casting values ​​using built-in conversion functions

ThisWillBeNumber = Number("15"); ThisWillAString = String(ThisWillANumber); ThisWillString = Format(ThisWillNumber,"");//it is possible to specify a formatting string for the value ThisWillDate = Date("201601+ThisWillANumber);//time will be 00:00:00 //Casting through an object CanOnlyBeNumber = New TypeDescription("Number") ; ThisWillBeNumber = CanOnlyBeNumber.GiveValue("12");

Please note that the system will not be able to make some transformations, and this will cause a runtime error, so the check must be carried out by the developer

ThisAssignmentWillNotHappen = Date("12:45:45");

Type checking

The comparison is made through the special functions TypeValue() and Type().

The first returns the value of the passed type, the second sets the type to be checked

ThisNumber = 15; //answer to the question: is the value type of the variable "ThisNumber" of type "Number" ThisBoolean = TypeValue(ThisNumber) = Type("Number"); //The first sign "=" is an assignment //The second "=" is a comparison for equality

The “Type” object itself is auxiliary and cannot be written to details

Comparison of values

Produced:

  • when comparing for equality based on a clear match between type and value, no casting is performed
  • comparison by > or< (на больше-меньше) допустимы только для значений совпадающих примитивных типов (Булево, Число, Строка, Дата)

I won’t go into more detail about the types; it’s better to get a feel for them in real problems or narrow examples

Since in program code we work with values, we periodically need to know their type. Type 1C is always indicated in the metadata of the details - in directories and documents.

Working with 1C types is often used:

  • Conditions in the program
  • Different actions depending on the type of 1C value in the “If ... Then ...” construction
  • Limitations when working in the interface
  • Prohibiting or allowing the user to enter values ​​of certain types of 1C into a field on the form.
  • Determining the actual function/procedure parameter
  • If a function/procedure parameter can be of any 1C type, then you need to define it in order to correctly obtain the value.

Type 1C can be obtained:

  • Determine the type of actual value 1C
  • Value objects have properties that indicate the allowed 1C type (for example, 1C types allowed in a table column, in a field on a form, in metadata) or methods that return these 1C types
  • From metadata - you can get the 1C type as it is specified in the metadata in the configurator.

Types 1C can be divided into three types:

  • Basic types 1C
  • Types of 1C databases (reference, objects)
  • Types 1C.

Definition of 1C type and comparison of 1C types

You can find out the type of value 1C using the function TypeValue (Variable)

To understand what 1C type this function returned, we need to specify the Type we need (“TypeName”)

For example, definition (comparison) of a type 1C variable:
If TypeValue(Variable) = Type("TypeName") Then

What types should I write as TypeName?

Basic types

Basic types of 1C - number, string, date, boolean.

For example:

Znch = 12; If ValueType(Value) = Type("Number" "String" ) Then ElseIf Value = Type("Date") Then ElseIf Value = Type("Boolean" ) Then endIf;

Database types

1C stores data in a database, but not in the form of individual records, but in the form of objects.

Most saved objects (including: directories, documents, enumerations, business processes, tasks) are available as an Object (for editing and writing) and as a Link (for reading). See "Links and Objects" for more details.

For example:

Value = Directories. Organizations. EmptyLink() ; If TypeValue(Value) = Type( "DirectoryLink.Organizations") Then ElseIf Value = Type( "DirectoryObject.Organizations") Then ElseIf TypeValue(Value) = Type( "DocumentLink. Receipt of Goods") Then ElseIf Value = Type( "DocumentObject.Receipt of Goods") Then endIf;

Registers can be of various types. The register type name is compound:
RegisterRegisterTypeAccessType.RegisterName

Types of 1C registers:

  • Information
  • Savings
  • Accounting
  • Calculation.

There are several types of register access. Most often used:

  • Set of Records
  • List
  • Sample
  • Record
  • RecordKey.

Example:
If TypeValue(Value) = Type("InformationRegisterList.RegisterName") Then
OtherwiseIf Value = Type("AccumulationRegisterRecordSet.RegisterName") Then
endIf;

Types 1C

The 1C language allows you to work with many objects created dynamically in the program, for example, an array, a list of values, a table of values, a structure...

Such 1C types are indicated by their name (in one word, without spaces). For example:
If TypeValue(Value) = Type("Array") Then
ElseIf Value = Type("List of Values") Then
endIf;

Determining the value of a 1C reference type

Work with all database objects (directories, documents...) is carried out through links. For example, if we want to make a reference in a document, then its 1C type will be “DirectoryLink.DirectoryName”.

For example:

Value = Directories. Organizations. EmptyLink() ; If Directories. TypeAllLinks() . Contains(TypeValue(Value)) Then //this is the directory OtherwiseIf Documents. TypeAllLinks() . Contains(ValueType(Value)) Then //this is a document endIf;

Working with 1C types in a request

In a request, the 1C type can be checked in two ways.

To check the type of a field in a 1C 8.3 request, you can use the query language function VALUE TYPE(<Поле>).

WHERE VALUES TYPE(Table.Sum) = TYPE(NUMBER)

Function TYPE(<Имя типа>) gets a type by its name. Primitive type names: Number, String, Boolean, Date. The names of reference types are constructed according to the following principle: Document. Sales of Goods and Services or Directory. Nomenclature.

SELECT Self-supportingTurnover. Subconto1, Self-supportingTurnover. Subconto2, Self-supportingTurnover. Subconto3, Self-supportingTurnover. AmountTurnover, SELECTION WHEN VALUES TYPE(Self-supportingTurnover. Subconto3 ) = TYPE(Document. Sales of Goods and Services) THEN "Sales" WHEN VALUES TYPE(Self-supportingTurnover. Subconto3 ) = TYPE(Document. Receipt Cash Order) THEN "PKO" WHEN VALUES TYPE(Self-supportingTurnover . Subconto3 ) = TYPE(Document . Expenditure Cash Order) THEN "RKO" OTHERWISE "Another document" END AS Document Type Calculations FROM RegisterAccounting. Self-supporting. Turnover(& Start of Period, & End of Period, Registrar, Account = & Account6201 , , , , ) AS Self-AccountingTurnover For fields of a reference type, there is another way to check using the REFERENCE operator.

CHOICE WHEN Self-supportingTurnover. Subconto3 LINK Document. Sales of Goods and Services THEN "Sale" WHEN Self-supportingTurnover. Subconto3 LINK Document. Receipt Cash Order THEN "PKO" WHEN Self-accountingTurnover. Subconto3 LINK Document. Expendable Cash Order THEN "RKO" OTHERWISE "Another document" END

Obtaining available 1C types

Many objects have a property.ValueType, which contains a list of 1C types:

Field on the fat client form
Form Elements.FieldName.ValueType
Field on the thin client form (exception: called AvailableTypes)
Elements.FieldName.AvailableTypes
Column of the table of values, tree of values
Form details
Selection element

How to work with this list of 1C types in the field.ValueType - see “Description of Types” in the “1C Language” section.

Working with types of 1C details in configuration metadata

When adding and editing details in the configurator, the programmer specifies the type(s) of 1C details. In the program code in the 1C language, you can get (find out) the type(s) of 1C details.

Basic methods:

For a 1C object, call the Metadata() method, which returns the metadata of a specific object and then work with the list of details (and details of the table section)

Use the global variable “Metadata”, which returns all configuration metadata, and then access the details of a specific object

Metadata.Documents.Receipt of Goods.Details

The attribute has a property.Type, which contains a list of 1C types set in the configurator for this attribute.

How to work with this list of 1C types - see “Description of Types” in the “1C Language” section.

Specify 1C type filter

For many objects it is possible to specify a filter of 1C value types that can be used, for example:

List of values ​​(.AvailableValues)
Managed Client Form Field (.AvailableTypes)
Where the filter is not available for modification, it is possible to specify the filter in the object method. For example, a column of a table (tree) of values ​​has.ValueType and we cannot change it, but when adding a column using the.Add() method, the second parameter can be used to specify a list of available 1C types.

To specify a list of 1C types for a filter, a list of 1C types is used; how to work with it, see “Description of types” in the “1C Language” section.

— we began to discuss what 1C value types are and the conversion of 1C types.

Today we will talk in more detail about the types of 1C configuration objects (1C document type, 1C directory type, etc.)

Since in program code we work with values, we periodically need to know their type. Type 1C is always indicated in the metadata of the details - in directories and documents.

Working with 1C types is often used:

  • Conditions in the program
    Different actions depending on the type of 1C value in the “If ... Then ...” construction
  • Limitations when working in the interface
    Prohibiting or allowing the user to enter values ​​of certain types of 1C into a field on the form.
  • Determining the actual function/procedure parameter
    If a function/procedure parameter can be of any 1C type, then you need to define it in order to correctly obtain the value.

Type 1C can be obtained:

  • Determine the type of actual value 1C
  • Value objects have properties that indicate the allowed 1C type (for example, 1C types allowed in a table column, in a field on a form, in metadata) or methods that return these 1C types
  • From metadata - you can get the 1C type as it is specified in the metadata in the configurator.

Types 1C can be divided into three types:

  • Basic types 1C
  • Types of 1C databases (reference, objects)
  • Types 1C.

Definition of 1C type and comparison of 1C types

You can find out the type of value 1C using the function TypeValue (Variable)

To understand what 1C type this function returned, we need to specify the Type we need (“TypeName”)

For example, definition (comparison) of a type 1C variable:
If TypeValue(Variable) = Type("TypeName") Then

What types should I write as TypeName?

Basic types

Basic types of 1C - number, string, date, boolean.

For example:
Znch = 12;
If TypeValue(Value) = Type("Number") Then
ElseIf Value = Type("String") Then
ElseIf Value = Type("Date") Then
ElseIf Value = Type("Boolean") Then
endIf;

Database types

1C stores data in a database, but not in the form of individual records, but in the form of objects.

Most saved objects (including: directories, documents, enumerations, business processes, tasks) are available as an Object (for editing and writing) and as a Link (for reading). See "Links and Objects" for more details.

For example:
Value = Directories.Organizations.EmptyLink();
If TypeValue(Value) = Type("DirectoryLink.Organizations") Then
OtherwiseIf Value = Type("DirectoryObject.Organization") Then
OtherwiseIf TypeValue(Value) = Type("DocumentLink.Receipt of Goods") Then
OtherwiseIf Value = Type("DocumentObject.Receipt of Goods") Then
endIf;

Registers can be of various types. The register type name is compound:
RegisterRegisterTypeAccessType.RegisterName

Types of 1C registers:

  • Information
  • Savings
  • Accounting
  • Calculation.

There are several types of register access. Most often used:

  • Set of Records
  • List
  • Sample
  • Record
  • RecordKey.

Total, example:
If TypeValue(Value) = Type("InformationRegisterList.RegisterName") Then
OtherwiseIf Value = Type("AccumulationRegisterRecordSet.RegisterName") Then
endIf;

The 1C language allows you to work with many objects created dynamically in the program, for example, an array, a list of values, a table of values, a structure...

Such 1C types are indicated by their name (in one word, without spaces). For example:
If TypeValue(Value) = Type("Array") Then
ElseIf Value = Type("List of Values") Then
endIf;

Determining the value of a 1C reference type

Work with all database objects (directories, documents...) is carried out through links. For example, if we want to make a reference in a document, then its 1C type will be “DirectoryLink.DirectoryName”.

For example:
Value = Directories.Organizations.EmptyLink();
If Directories.TypeAllLinks().Contains(TypeValue(Value)) Then
//this is a reference book
ElseIf Documents.TypeAllLinks().Contains(TypeValue(Value)) Then
//this is a document
endIf;

In a request, the 1C type can be checked in two ways.

The first is similar to that described, but the 1C type name does not indicate “Link” or “Object”, that is, instead of “DirectoryLink.Organizations” we write “Directory.Organizations”

For example:

Obtaining available 1C types

Many objects have a property.ValueType, which contains a list of 1C types:

  • Field on the fat client form
    Form Elements.FieldName.ValueType
  • Field on the thin client form (exception: called AvailableTypes)
    Elements.FieldName.AvailableTypes
  • Column of the table of values, tree of values
  • Form details
  • Selection element

How to work with this list of 1C types in the field.ValueType - see “Description of Types” in the “1C Language” section.

Working with types of 1C details in configuration metadata

When adding and editing details in the configurator, the programmer specifies the type(s) of 1C details. In the program code in the 1C language, you can get (find out) the type(s) of 1C details.

Basic methods:

  • For a 1C object, call the Metadata() method, which returns the metadata of a specific object and then work with the list of details (and details of the table section)
    Documents.Receipt of Goods.EmptyLink().Metadata().Details
  • Use the global variable “Metadata”, which returns all configuration metadata, and then access the details of a specific object
    Metadata.Documents.Receipt of Goods.Details

The attribute has a property.Type, which contains a list of 1C types set in the configurator for this attribute.

How to work with this list of 1C types - see “Description of Types” in the “1C Language” section.

Specify 1C type filter

For many objects it is possible to specify a filter of 1C value types that can be used, for example:

  • List of values ​​(.AvailableValues)
  • Managed Client Form Field (.AvailableTypes)

Where the filter is not available for modification, it is possible to specify the filter in the object method. For example, a column of a table (tree) of values ​​has.ValueType and we cannot change it, but when adding a column using the.Add() method, the second parameter can be used to specify a list of available 1C types.

To specify a list of 1C types for a filter, a list of 1C types is used; how to work with it, see “Description of types” in the “1C Language” section.

1C allows you to significantly simplify accounting or simply manage any organization, be it a small store or a large enterprise. The program is a large database management system. In order not to get confused in all this, you need to be able to perform various simple actions and understand the essence. Next, you will understand how to check the type of value in a request in 1C, as well as what they generally are, as well as how to distinguish between them.

Value types

1C: The enterprise has included a special function in new versions (platform 8.2). Using it, you can add any special parameters to any names or elements of the data system. This was done to make the system easier to edit and add new elements to. This function is called “Value Type”.

In fact, this is one of the basic concepts that most programming languages ​​contain. Using it, you can classify various data. For example: dates, numbers, strings, links. These are just basic classifications. There may be many more of them. Let's say, if you enter information about cities into your system, you can use: continent, country, region, etc.

Examination

You can check a particular field using a query language. Or rather its functions: TYPE VALUE. That is, if we want to find out what type of information the cell of interest contains, we must use the command.

VALUE TYPE(Value) = TYPE(String)

In the example above, we defined the simplest type using the command. Another example of request validation:

Documentation

There are quite a few types; users can make do with the initial ones or enter their own to improve the information base. Here are some of them.

  • DocumentLink. It is used for conveniently storing references to various objects within other parts of the system.
  • DocumentObject - editing documents.
  • DocumentSelection - sorting through objects from the database.

In addition, there are special terms that characterize any data:

  • form;
  • line;
  • boolean;
  • number;
  • date of;
  • array;
  • checkbox;
  • picture.

These are just some of them. Any object can only be something from this list. Boolean is a special parameter that takes two values: true or false. There are also special tags that allow you to adjust the request: when, where, how, otherwise, etc. They set the program’s behavior algorithm. 1C is distinguished by the fact that these words here, like everything else, can be entered in Russian.

It is important to understand that all this will be perceived by beginners and non-professionals as Chinese literacy. To understand what we are talking about and effectively use 1C, you need to know the basics of programming. In general, checking the type in a request in the 1C program will be quite easy in comparison with other actions.