1s if in the list of values. Additional Methods for Array

Full syntax (click to expand)

List of Values

Description:

A list of values ​​is an object not stored in the database that allows you to build dynamic sets of values ​​for solving interface problems and manipulate them (add, edit, delete elements, sort). It can be filled with values ​​of any type, i.e. in one list, the types of stored values ​​can be different. One example of using this object is organizing the selection of a specific document from a list of possible documents generated by a complex algorithm.

Collection elements: ItemListValues

It is possible to traverse the collection for an object using the operator For each ... From ... Cycle. The traversal selects the elements of the collection.

It is possible to access an element of a collection using the [...] operator. The element index is passed as an argument ( numbering from 0).

Properties:

Methods:

Insert(Index, Value, View, Markup, Image) Inserts a new element into the list of values ​​at the position at the specified index.SelectElement (Header, Element) Calls up a window for interactively selecting one of the elements included in the list of values. Element- the element on which the list of values ​​should initially be positioned during interactive selection. If the value of the parameter is not an element of the list of values ​​included in this list, positioning will not occur.UploadValues()Creates an array and copies the values ​​of the elements of the list of values ​​into it.Add(Value, View, Markup, Image) Adds a new element to the end of the list of values.DownloadValues(Array of Values) Loads a list of values ​​with values ​​from the passed array. In this case, all previous elements of the list are deleted.Fill in Notes(Label) Sets the label for all elements of the list of values.Index (Element) Gets the index of the element in the list of values. If not found, then -1 is returned.count() Gets the number of elements of the list of values.FindByValue(LookupValue) Looks up the value of an element of a list of values. If no element stores a value equal to the desired value, then the value is returned. Undefined. FindByID(ID) Gets the element of the list of values ​​by ID. If the element is not found, then returns Undefined. Mark Items(Title) Checks or unchecks (interactively) the items in the list of values. returns True if the "OK" button is pressed in the dialog, Lie- otherwise.Clear() Clears the list of values ​​by removing all elements from it.ShowItemSelection(ClosingAlertDescription, Title, Item) Calls a window to interactively select one of the items in the list of values.ShowMarkItems(DescriptionNotificationsOnClosing, Header)Designed for interactive setting of flag states for elements of the list of values.Get(Index) Gets the value at the index. Works similar to the operator.Move (Item, Offset) Moves an element of the list of values ​​forward or backward by the specified number of positions.Copy() Creates a copy of the list of values.SortByValue(Direction) Sorts the list of values ​​in ascending or descending order of the values ​​stored by the elements. See example below.SortBy View(Direction) Sorts the list of values ​​in ascending or descending alphabetical order of the representations of the member values ​​in the list. See example below.Remove (Element) Removes an element from the list of values ​​where Element- the index of the element to be removed, or the element itself.

Constructors:

New List of Values
&OnClient Procedure ExecuteCode(Command) /// How to create a list of values ​​in 1s 8.3, 8.2 List = New List of Values; /// How to add an element to the list of values ​​in 1s 8.3, 8.2 // add method parameters:// - meaning // - representation // - mark (optional) // - picture (required) List. Add( 1980 , // element value "Year of Vasya's birth"// representation ) ; List. Add(1985 , "Yulia's birthday") ; // values ​​can be of different types List. Add("Polina" , "Child's name" ) ; /// How to insert an element into the list of values ​​in 1s 8.3, 8.2 // insert at position #2 (elements are numbered from 0) // element with value 2010 and representation // "Year of birth of their joint daughter" List. Paste(2 , 2010 , "Birth year of their joint daughter") ; /// How to bypass the elements of the list of values ​​in 1s 8.3, 8.2 For Each Element From List Loop Report( Element. View + ": " + String(Element. Value) ) ; EndCycle ; /// How to clear the list of values ​​in 1s 8.3, 8.2 List. Clear() ; List. Add("Monday" ); List. Add("Tuesday" ); List. Add("Wednesday" ); /// How to find out the number of elements of the list of values, and also /// get a list element by its index in 1s 8.3, 8.2 // numbering from zero For Index = 0 By List. Quantity() - 1 Loop Report(List[Index] ) ; EndCycle ; /// How to find a list element by its value in 1s 8.3, 8.2 ValueTuesday = List. FindByValue("Tuesday" ) ; /// How to find out the index of an element in the list in 1s 8.3, 8.2 Report(List. Index(ValueTuesday) ) ; // 1, since the numbering is from zero /// How to sort the list by its values ​​in 1s 8.3, 8.2 // was: Monday, Tuesday, Wednesday List. SortByValue(SortingDirection. Descending) ; // became: Wednesday, Monday, Tuesday /// How to remove an element from the list of values ​​in 1s 8.3, 8.2 // remove the first element // parameter: list element // or element index// you can do this List. Delete(List[ 0 ] ) ; // or so // List.Delete(0); /// How to shift an element of the list of values ​​in 1s 8.3, 8.2 // shift the zero element one position forward // was: Monday Tuesday List. Move(0 , 1 ) ; // became: Tuesday Monday /// How to make a copy of the list in 1s 8 ListCopy = List. Copy() ; Colors = New ValueList; Colors. Add("Red" ); Colors. Add("Green" ); Colors. Add("Blue" ); /// How to unload list values ​​into an array in 1s 8.3, 8.2 ArrayColors = Colors. UnloadValues() ; /// How to load list values ​​from an array in 1s 8.3, 8.2 Colors. LoadValues(ArrayColors) ; EndProcedure /// How to make a modeless selection of a value from a list /// values ​​in 1s 8.3, 8.2&OnClient Procedure How toMakeModalSelectValue(Command) Colors = New ValueList; Colors. Add("Red" ); Colors. Add("Green" ); Colors. Add("Blue" ); // procedure AfterItemSelect is defined just below AlertAfterItemSelection = New AlertDescription( "AfterElementSelection", ThisObject ) ; Colors. ShowItemChoice( AlertAfterItemChoice, "Choose your favorite color") ; EndProcedure &AtClient Procedure AfterElementSelection(Element, Parameters) Export If Element<>Undefined Then Report(Item. Value) ; EndIf ; EndProcedure /// How to make a non-modal mark of values ​​from a list /// values ​​in 1s 8.3, 8.2&OnClient Procedure How toMakeModalValueMark(Command) Colors = New ValueList; Colors. Add("Red" ); Colors. Add("Green" ); Colors. Add("Blue" ); // procedure AfterMarkingItems is defined just below AlertAfterMarkItems = New AlertDescription( "AfterMarkingItems", ThisObject ) ; Colors. ShowItemMark( NotificationAfterItemMark, "Choose your favorite colors") ; Colors. FillRemarks(True) ; EndProcedure &OnClient Procedure AfterMarkingElements(Elements, Parameters) Export If Elements<>Undefined Then For Each Color From Elements Loop If Color. Flag Then Report(Color. Value) ; EndIf ; EndCycle ; EndIf ; EndProcedure /// How to make a modal selection of a value from the list in 1s 8.3, 8.2&At the Client Procedure How toMakeModalSelectValue(Command) Colors = New ValueList; Colors. Add("Red" ); Colors. Add("Green" ); Colors. Add("Blue" ); SelectColor = Colors. SelectItem( "Choose your favorite color") ; If Chose Color<>Undefined Then Report(SelectColor. Value) ; EndIf ; EndProcedure /// How to make a modal mark of values ​​from a list /// values ​​in 1s 8.3, 8.2&OnClient Procedure How toMakeModalValueMark(Command) Colors = New ValueList; Colors. Add("Red" ); Colors. Add("Green" ); Colors. Add("Blue" ); If colors. Mark Items( "Choose your favorite colors") Then For Each Color From Color Cycle If Color. Flag Then Report(Color. Value) ; EndIf ; EndCycle ; EndIf ; // and this is how you can set all the marks at once // list to a specific value Colors. FillRemarks(True) ; EndProcedure /// Download and run these examples on a computer

What is this article about

This article continues the series of articles "First steps in development on 1C". It discusses the principles of working with generic collections. After reading the article, you will know:

  • What are generic collections, when and in what cases should they be used?
  • What do all universal collections have in common? What techniques can be used to work with all of them?
  • What is an array, how and when to use it? What methods does he have?
  • Why use a structure? How is it different from an array?
  • When to use a list of values? How to display it on the form?
  • Compliance - what is it and when to use it? What are the advantages regarding structure?
  • What is a table of values ​​used for? How to describe its structure? How to add/remove lines? How to bring it to the form?
  • Value tree - what is it used for? How to fill out and display on the form? How to work with him?

Applicability

The article discusses the 1C:Enterprise 8.3 platform of the current edition.

How to work with universal collections in 1C

A collection of values ​​is a kind of container that can usually contain any number of elements. At the same time, there are often no strict restrictions on the data type.

You can add values ​​to a generic collection. All values ​​in the collection can be traversed. These collections are mainly used for some kind of processing in algorithms. Those. these are some dynamic structures that exist for the duration of the algorithm.

It is important to understand that collections are not stored in the database (we are not talking about the Value Store data type, which can store almost any data type).

There are different kinds of generic collections: Array, Structure, Mapping, Fixed Array, Value Table, Tabular Part, etc. But all collections have similar behavior.

A collection can be created as a result of some function (the function returns a generic collection as a value).

You can get the new collection manually by calling the constructor and creating an instance of the class.

For example: OurArray = New Array;

Constructors for many generic collections are parameterized.

So, in the constructor for you can specify the number of elements in the corresponding dimensions. Those. you can immediately declare multidimensional .

The corresponding description of the constructor is in the syntax helper.

Thus, using constructor parameters, you can immediately set the desired behavior of this object.

But the parameters are optional, the developer can not set them and further define the behavior of the Array as he sees fit.

Almost any generic collection can be created using a constructor (with the exception of tableparts, which act as configuration objects).

For generic collections, there are such general concepts as index and number. Each element of the collection has an index. The index starts from zero.

To access an element OurArray, you can use index access, for this the index is indicated in square brackets.

For example, OurArray. Note that in this case the system returns the element of the Array at index 3, and in order this is the fourth element of the Array.

For some collections, there is also the concept of a row number. The line number starts with one. For example, for a tabular section there is such a property as a row number. It is important to keep in mind that if we know the row number and want to access by index, then the value one less than the row number should be used as the index.

The concept of a line number does not exist for all collections, but mainly for those that can be displayed in the user interface.

For all collections, traversal of the elements of the collection is used. Bypass is possible in two ways: cycle For And cycle For each.

For most generic collections, the following methods apply: Count, Index, Add, Insert, Delete, and Find.

Count is a function that returns the number of elements in a collection. It can be used before the loop For, as shown in the figure.

The Index method does not exist for all collections, but only for those whose elements can be referenced. An example is Value Table.

Value Table is a specific collection of strings, strings can contain different columns with different types of values.

Each line is an independent entity. You can get a link to it, through this line you can access the values ​​of the columns in this line.

The Index method allows you to determine which index corresponds to a given row (that is, the current position of the row in the table). Index values ​​start at zero.

Methods for adding new values ​​to this collection exist in almost any generic collection. The figure shows how to fill an Array with values ​​from 0 to 10 in two ways.

To add an element to an Array, we can use the method Add, indicate the added value in brackets. In this case, the value will be added to the end of the list, i.e. The array will constantly increase due to the last position.

Another method that allows you to add values ​​to a collection is the method Insert. It differs from the method Add so that you can specify where to insert the added element.

Syntax: Insert (,)

The first parameter specifies the index into which the new value will be inserted. Those. we, for example, can specify that each value should be inserted at the beginning of the list (the second way in the figure above).

The method is used to remove elements from a collection. Delete. In the Delete method, it is indicated by index which element we will delete.

Syntax: Delete()
Usage example: OurArray.Delete(5);

It should be noted that for those collections where strings represent an independent entity (for example, for TableValues), we can also use the get index method to remove the given row later.

Almost all collections have a method for finding a value - To find. The method is passed the value that we want to find. In some collections, you can put any restrictions.

For example, in Value Table you can specify those rows, those columns in which you want to search.

If the value is found, then this method returns the index or a specific string. If no value is found, a value of type is returned. Undefined. When applied to an Array, returns Index, or the value Undefined.

Usage example: OurVariable = OurArray.Find(8);

Generic collections can be cleaned up very quickly, i.e. remove absolutely all elements. For this, the method is used clear(), which removes the elements of an Array, strings TableValues, or data from other collections.

Additional Methods for Array

Method Bboundary() returns the number of elements minus one. Those. if we use a loop For, then instead of the Quantity method, we can immediately use the method Border().

In particular, the variable NumberInArray could have been defined differently:

NumberInArray = OurArray.InBorder();
Then, when describing the cycle itself, one should not be subtracted from this variable.

The Set method allows you to assign a value to an Array element by index.

Syntax: Install(,)

Example: OurArray.Set(2,8);

Alternative option: OurArray = 8;

You can use the method for an Array Receive, in order to read the value at index without resorting to the use of square brackets.

Syntax: Receive()

Example: OurVariable = OurArray.Get(2);

Alternative option: OurVariable = OurArray;

Universal Collection Structure

A structure, like an Array, can have an unlimited number of elements, but the content of an element differs from an Array.

The structure is a collection, each value of which consists of a pair. The first element of a pair is called Key. The second element of the pair is Meaning.

Key is a strictly string data type that describes a value. For example, Key"Code" can correspond to the value 113; Key"Name" meaning "Vasya". There is no data type constraint on the Value itself.

The structure is very convenient to use if we want to create a list of parameters. If this Structure called OurStructure, then we will refer to its two values ​​as follows: OurStructure.Code and OurStructure.Name.

Such an appeal is much more convenient than if we defined all the parameters in an Array and accessed them by index.

The structure makes the program code readable (understandable). The structure is used quite often, much more often than the Array.

It is used to describe some parameters, which are often quite large in all algorithms.

In addition, the Structure is used if the procedure and function contain a large number of passed parameters.

Then it is much more convenient to write all the parameters into the Structure and pass it on. Those. there is a "packing" of parameters of procedures and functions.

Separately, it should be noted that as key not absolutely any string can appear in the Structure. Certain restrictions apply.

Key should act as an identifier. This means that in key there must be no spaces and it cannot start with a number.

Permissible start key with a letter or underscore. In this way, Key must satisfy the requirements for creating identifiers.

Let's note how the Structure differs from the Array. The struct has a method Insert, Array has two methods for insertion: Insert(to a certain position) and Add(at the end of the list). In an Array, all elements are ordered.

A structure is a kind of unordered set. That is why there is only an insert method for a Struct.

The value is inserted not at a specific position, but into the specified set. A Struct cannot be referenced by index like other generic collections.

The elements of the Structure are referred to only by the name of the Key. However, the For each of loop also works for the Structure, but you should not rely on the order of the elements of the Structure.

A structure is created in the same way as other generic collections by using the New constructor, specifying the data type of Structure.

Like an Array, a Struct's constructor can have parameters. Those. it is possible to describe the contents of the Structure itself using a constructor.

Unlike an Array, where you can simply specify the number of elements for all dimensions, in a Structure it is possible to set the content itself.

For example: OurStructure = New Structure("Code,Name", 133, "Vasya");

First, the names of the Keys are listed separated by commas, and then, respectively, in the same sequence, the values ​​of the parameters.

To add a new value to the Structure, there is a method Insert, which inserts a new pair (Key and Value).

For example: OurStructure.Insert("Family Members",3);

The Structure is characterized by another method that is used quite often. This is the method Property.

Using this method, you can understand if there is such an element in this Structure, for which the Key has such and such a name.

If such an element exists, the system will return True, otherwise it will return False.

For example, the expression OurStructure.Property (“Family Members”) will be equal to True. This method is used quite often in the analysis of the Structure.

As for any universal collection, it is permissible to access the properties of the Structure by index. But the index for the Structure is a string value.

For example: Report(OurStructure["Family Members"]);

However, one should not forget that a Structure is not an ordered set of objects, which is why access by index 0, 1, 2 is unacceptable.

Generic Collection List of Values

List of Values is a linear list of elements of any data type.

Each element consists of several values. Schematically, a list of values ​​can be represented as a list with four columns.

First column - mark. It has a boolean data type and allows the user to either check the boxes or uncheck them.

The other column is a picture that can somehow visually depict this element, i.e. match this line with any picture.

The third column is the stored value itself, i.e. this is any data type, and it can be different in different rows.

The fourth column is the view, i.e. it is some string description of the given value. The view will be displayed to the user when he views this element. In this case, if the view is not set, the system will try to get views for the element contained in this position.

List of Values- this is the object with which the user can visually work. Those. List of Values can be displayed on the form.

The user can perform some actions with it. Besides, List of Values can be inferred independently using methods, i.e. show on the screen in some branch of the algorithm (with the exception of the server code), so that the user selects some line or puts some checkmarks.

Let's find List of Values in sitax helper. Constructor List of Values not parameterized (no default values ​​can be set).

There are methods like:

  • Insert(,) ;
  • Add(,);
  • Quantity();
  • Index().

There are also special methods, for example, UnloadValues(). This creates an Array into which the list of values ​​is copied. For example:

ArrayElements = ListPriceTypes.UnloadValues();

There is also a reverse method:
PriceTypeList.LoadValues(ElementsArray);

There are search methods:
FindByValue(); FindByIdentifier().

There is a copy method:
CopyList = ListPriceTypes.Copy();
This method is intended to make some kind of modification with a copy.

There are methods:
SortByValue();
SortByView().

Methods SelectItem(,) And MarkItems() call a modal dialog box that stops the execution of the algorithm until the user closes this window.

To use these methods in configuration properties Modality usage mode must be set to Use.

Sample code called from a Managed Application module:

Display this code in user mode (modal dialog box).

Below List of Values used as the available data type for the form attribute. We create a new attribute for the processing form, determine the type for it List of Values and display it on the form.

We create a new team StoreGifts, transfer it to the form and define an action handler for it.

In user mode, when you click the Fill in Gifts button in the processing form, a completed list will appear.

If desired, the list can be edited: add some elements, remove some.

Universal Collection Compliance

This collection is very similar to structure. Just like a Struct, a Match is a set of values ​​that consists of a key and the value itself.

The main difference is that any data type can be specified as a Key, as well as for a value. In view of this feature, it is necessary to access the match value by index, the key value is specified as the index value.

The key can be a data type other than a string. The properties and methods of working with Matching are almost the same as those of the Structure.

The Match Constructor, unlike a Struct, does not contain the ability to specify parameters.

Usage example:

Correspondence is useful when it is necessary to link any two structures. For example, each row of the tabular part must be matched with a row from the table of values.
In this case, the row of the tabular section is used as the Matching key and the corresponding value is indicated.

When inserting elements into a Match collection other than the method Insert(,) There is another way to insert a value, and that is to use the normal assignment operator.

For example: OurMatch = New Match;
Match = 999;

Those. if the element was not present in the collection, then it will be added using the assignment operator, and if present, it will be updated.

This is different from Structure.

Generic Collection Table of Values

Value Table is a table with an arbitrary number of rows and an arbitrary number of columns. An intersection can store values ​​of any data type. If necessary, columns can be typed, i.e., determine in which column which type of data is stored.

You can leave the columns untyped, then the same column in different rows can store values ​​of different types.

Differences TableValues from a 2D Array:

  • this is an object that the user can work with (the table of values ​​can be displayed on the screen, the user can fill it in, in the future the entered data can be read);
  • building indexes for fast searching;
  • cloning, filling the entire column with a certain value, unloading all columns into an array.

Value Table used as a kind of buffer for storing information. Value Table is returned and accepted as a parameter by many of the system's methods. It is possible to build a query to the Table of Values.

So, Value Table consists of a set of rows and a set of columns. Both rows and columns are collections.

Those. inside the collection Value Table there are two more collections. Let's turn to the syntax assistant and find Value Table.

Supported data types: itself Value Table, which consists of strings. Each row is represented by a data type RowTableValues, which has its own properties and methods. Available CollectionColumns TableValues also has certain properties.

Important point! The procedure that generates Value Table, should compile & OnServer.

Before you start working with Value Table, you need to determine which columns it will contain (i.e. create them). Syntax:

Add(,)
(optional)
Type: String.
(optional)
Type: Description Types
(optional)
Type: String.
(optional)
Type: Number.

For example:

To call this procedure, we will use the command.

In description TableValues as elements of the collection are exactly RowsTableValues.

Unlike columns, which consist only of properties (Name, Type, Title, Width), in RowTableValues there are both properties (reference by column name) and methods (you can get and set a value, work with owners).

To add a new row to the table, you need to use the method either Add(), or Insert(). In the second case, you should specify which position the required string should be placed in.

To assign a value to a column, we refer to it by the column name or index (using square brackets) separated by a dot.

For filling TableValues the following methods can be used:

clear()- to remove all rows from TableValues.

FillValues(,)– allows you to fill all columns or selected columns with one value.
LoadColumn(,)– loads a column from an array.
UnloadColumn()– unloads a column into an array.

The last two methods are useful when you need to move a column from one table of values ​​to another.

Copy(,)- allows you to create a new table based on an existing table Value Table, while specifying not all rows and all columns, but only some of them. Return value - Value Table.

You can copy the structure TableValues. There is a corresponding method for this. CopyColumns(). We will receive an empty Value Table with the desired structure.

IN Value Table there is a method total(). You can specify the column in which you want to sum the numerical values. With regard to the previously shown code in the Tableau, you can calculate the value: TK.Total(“Sum”).

IN Value Table it is possible to group (collapse) numerical values ​​by the same values ​​of certain columns using the method Collapse(,).

With regard to the previously shown code in the Tableau, you can calculate the value: TK.Collapse(“Day of the Week”, “Amount”).

Value Table can be shown on the user's screen so that you can perform any actions with it. But unlike List of Values from the program code, you can’t just call the table on the screen.

To display Value Table on the screen, create a form attribute and assign it a data type Value Table.

After that, the resulting table should be displayed on the form.

In the form module, at the end of the previously compiled algorithm (in the Procedure for Creating a Table of Values), add:
ValueVFormData(TK, Table);

Generic Collection Tree of Values

a versatile collection that is very similar to Value Table. The difference from the table is that the rows of the tree can be subordinate to each other, i.e. some kind of hierarchy can be formed.

It can also be displayed on the screen. The value tree explicitly consists of a collection of rows and a collection of columns. There are two properties in the tree, Rows and Columns.

Since rows can be subordinate to each other, then for each row a Parent can be specified, as well as rows subordinate to it.

Let's create the appropriate Tree command and its processing procedure.

Let's create in which there is one parent row and two subordinate rows.

Create a form attribute DerZn(data type - Value Tree).

For this attribute, we will create the Year and Month columns.

Move the corresponding element DerZn to the form.

In the end Procedures TreeOnServer() add:

ValueVFormData(TreeZn, DerZn);

Let's check what happened in user mode.

With button Add you can add new lines. They can also form a hierarchy.

To iterate over all elements of the value tree, we need to use recursion, i.e. calling a procedure from itself. For example, processing a value tree might look like this:

This concludes our first introduction to universal collections.

In the next article, we will look at what important mechanism a developer can use to simplify accessing a dictionary element from program code.

In this unit, we will get acquainted with a new data type of the 1C language, which is called ValueList.

List of values is an array, but with more features. And if so, then it is also a collection of data and you can put a set of numbers in it:

// created a list of values

List.Add(23);

So far, everything is very similar to an array, isn't it? But let's move on. To now display these numbers to the user, we write:

// Loop through each element of the list For Each Element From List Loop Report(Item.Value);

// display the value of the EndCycle element;

And here is the first difference. The elements of an ordinary array are the numbers themselves. And access to the current value of the element List we get with option Meaning, using the construction Element. Meaning.

Consider some additional features Values.

Can sort

For example, we can easily sort a list of values. The list can do this by itself:

List.SortByValue(SortingDirection.Asc); In the case of an ordinary array, we would have to implement one of the sorting algorithms (for example, "bubble").

Can search

The list of values ​​is able to search for its own elements. Let's say we want to find out if the number entered by the user is in our list:

EnterNumber(Number); // entered a number from the user FoundItem = List. FindByValue(Number);

If FoundItem = Undefined Then OpenValue("Number " + Number + " not found in the list!"); Otherwise

OpenValue("Number " + Number + " is in the list. Here it is:" + FoundItem.Value);

EndIf; List of Values

Supports insertion and deletion

A list of values, like an array, supports insertion and removal of elements:

List. Insert(0, 1000);

// insert a thousand at the very beginning of the list List.Delete(O); // and immediately remove it from the list List. Insert(List.Quantity(), 13);

// insert 13 at the end of the list Report(List[List.Count() - 1]);

// display the last element of the list (13)

Supports square brackets

As you already understood, the numbering of the elements of the list also starts from zero, and we can refer to any element by its index using square brackets:

Notify(List.Value); // deduced the second element of the list Thus, we can go over all the elements of the list like this:

For A = 0 By List.Quantity() - 1 Loop Report(List[A].Value);

EndCycle;

Able to create a copy

The list of values ​​​​has just a great opportunity - it can create its own copy:

ListCopy = List.Copy();

// made a copy of the list // now we can safely change the Copy of the List // while the original list will not change the Copy of the List. Value = 123456;

Can be converted into an array

And finally, you can easily unload all the elements of the list into an array at any time:

ArrayNumbers = List. UnloadValues();

// unloaded into an array

For A = 0 By ArrayNumbers.Quantity() - 1 Loop

Report(ArrayNumbers[A]); // no need to specify // option Value

EndCycle;

To work out and consolidate the material of this unit, it is recommended to complete the following task.

It is necessary to enter 5 numbers from the user, find the largest and smallest of them and display them to the user. The solution must use a list of values.

Solution

List = New List of Values;

// created a list of values ​​For A = 1 By 5 Loop Number = 0;

EnterNumber(Number); // enter a number from the user List.Add(Number); // and add it to the EndCycle list; // and so 5 times

// sort the list of numbers

List. Sort By Value(Sorting Direction. Asc);

// after sorting, the first element of the list is // the smallest element, and the last element is the largest OpenValue("The smallest element" + List +

", and the largest one is " + List[List.Count() - 1]);

Share with friends or save for yourself:

Loading...