Dim means. What is dim and why does a woman need it?

For some time now, among the concepts of household electrical engineering, the word dimmer has been increasingly heard. What kind of device is this? For what purposes is it intended? Could it be another whim? Or a really necessary thing in everyday life? There are a lot of questions, we will try to give detailed answers to everything.

Purpose

The word “dimmer” comes from the English “dim”, which literally means “to darken” in Russian. But Russians themselves often call a dimmer a dimmer, because it is an electronic device with which you can change electrical power (that is, adjust it up or down).

Most often, such a device is used to control the lighting load. The dimmer is designed to change the brightness of the light emitted by LED lamps, as well as incandescent and halogen lamps.

The simplest example of a dimmer is a variable resistor (or rheostat). Back in the 19th century, German physicist Johann Poggendorff invented this device so that it could be used to regulate the voltage and current in an electrical circuit by increasing or decreasing resistance. A rheostat is a resistance-adjustable device and a conductive element. Resistance can change stepwise and smoothly. To obtain low brightness of light, it is necessary to reduce the voltage. But the resistance and current will be high, which will lead to strong heating of the device. So such a regulator is completely unprofitable; it will operate with low efficiency.

Autotransformers can also be used as a dimmer. Their use is due to their high efficiency; throughout the entire adjustable range, an almost undistorted voltage will be produced with the required frequency of 50 Hz. But autotransformers are quite large, weigh a lot, and require considerable mechanical effort to control them. In addition, such a device will be expensive.

Electronic dimmer - this option is the most profitable from an economic point of view. It is compact and has a slightly different operating principle. Let's talk about it in more detail.

Application

What a dimmer is is more or less clear. Voltage is supplied to the lamp, we change its level and thus adjust the brightness of the lamp. Now a few words about when and where this device is used.

Agree, quite often situations arise when it is necessary to reduce the brightness of the light:

  • often the flow of lighting needs to be reduced in the bedroom before going to bed;
  • Some design rooms require changes in the light pattern;
  • Sometimes indoor lighting is switched to the so-called standby mode in order to reduce energy consumption.

In industrial and domestic premises, LED lamps are configured for different consumption modes. At the same time, optimal lighting is selected and due to this, significant energy savings are achieved.

As for design ideas, it has now become fashionable in large living rooms or halls to use secondary lighting of individual areas. Secondary lighting is thought out to the smallest detail, and with the help of dimmers you can increase the lighting and focus attention on some interior details (a painting on the wall, a beautiful vase installed in a niche, etc.) Thus, with the help of lighting, the necessary thing comes out in the room first plan.

LED lamps, adjustable using dimmers, allow you to get a colorful effect during some concerts, advertising or special events.

The dimmer is very convenient for home parties. When guests are sitting at the table, bright lighting is required, but during dancing you can dim it. It is especially comfortable and beneficial to use such a device during a romantic dinner or date, when it is not necessary for the lamp to be on at full power.

And these are just some of the general examples. Surely, everyone has their own option for using dimmers. So this thing is necessary, convenient and cost-effective; you can install it at home and recommend it to your friends.

Device and principle of operation

Now, as they say, let's look at the dimmer from the inside. What kind of device is this, and what elements does it consist of? What is its operating principle based on?

All modern electronic dimmers have a key in their design as a main element (it can also be called a switch or switch), which is controlled by semiconductor transistor, triac or thyristor devices. Most devices do not produce a sinusoidal signal at the output; the electronic key, as it were, cuts off sections of the sinusoid.

To make it clearer, a current flows in the electrical network, which has a sinusoidal shape. To change the brightness, you need to apply a trimmed sine wave to the lamp. A bidirectional thyristor cuts off the leading or trailing edge of a sinusoidal AC wave, thereby reducing the voltage supplying the lamp.

Depending on which front of the sine wave is cut off, the adjustable method differs:

  • leading edge adjustment;
  • falling edge adjustment.

Both of these methods are used to control different lamps:

  1. Dimming of LED and halogen lamps is carried out using electronic transformers, and adjustment is applied along the trailing edge.
  2. Compact fluorescent and LED lamps with a voltage of 220 V, as well as low voltage lamps, are regulated using electromagnetic transformers and using the leading edge method.

Both of these methods are suitable for incandescent lamps.

The design of the dimmers also includes protection against short circuits and overheating.

Since dimmers are capable of generating electromagnetic interference, to reduce their level, a choke or inductive-capacitive filters are connected in series to the circuit.

For more information about a typical dimmer circuit, watch this video:

Advantages and disadvantages

The first dimmers were mechanically controlled and had one single function - to change the brightness of the lamp.

A modern regulator has a number of other functions:

  1. Automatic switching on and off.
  2. Can be controlled remotely via radio, voice command, acoustic change (noise or clap), via infrared.
  3. The touch-sensitive lighting controller allows you to smoothly turn the lamp on and off. Due to this, it is possible to avoid sudden surges of current through the lamps, as a result of which the latter often burn out.
  4. Dimmers are used to simulate presence. This is a particularly cool feature that will help keep “uninvited guests” away from your home when no one is home. A special program is set, according to which the dimmer automatically turns on and off the lights in different rooms. The illusion is created that the owners are at home.

Like any technical device, a dimmer cannot be one hundred percent universal; it has its drawbacks:

  • causes electromagnetic interference;
  • the output voltage has a nonlinear dependence on the value of the resistor in the electronic dimmer circuit;
  • Fluorescent lamps cannot operate from it, as well as lamps that light up through ballasts;
  • the output voltage of electronic dimmers has a non-sinusoidal shape, so it is not recommended to connect step-down transformers to it;
  • when working with incandescent lamps, low efficiency.

What types of dimmers are there?

According to the method of adjustment, there is a touch dimmer, mechanical, acoustic and remote.

Let's start with the simplest ones - mechanical ones. If we consider the type of execution, we can distinguish the following types of dimmers:

  1. Modular. They regulate lighting in public places (staircases, corridors, entrances). This type of device is mounted in a distribution panel; direct adjustment is carried out by a push-button or single-key switch.
  2. Monoblock. It is installed to break the phase of the circuit that goes to the lighting load and performs the functions of a switch.
  3. The block version is when the dimmer is mounted together with a switch (like a socket-switch unit).

Most often, monoblock dimmers are used in everyday life, which differ in the control method:

  • Turning. This dimmer has a knob that rotates. If you set it to the leftmost position, the lighting is turned off. If you gradually turn the knob to the right, the brightness of the lamp will increase.
  • Key. This device is very similar in appearance to a regular two-key switch. In this case, one key turns the lamp on or off, and the second is used to adjust the lighting power (by holding the key).
  • Turn-push. The principle of operation is the same as that of a rotary device, only to turn on the lighting, the handle is recessed a little.

Touch-sensitive lighting controllers are very popular now; they have a beautiful appearance and look harmonious in any interior (especially in high-tech style). Adjustment is carried out by touching the touch buttons.

Dimmers with remote control are considered the most convenient. This is well deserved, because using the remote control you can adjust the brightness of the lighting fixture from anywhere in the room.

Acoustic dimmers are most often used when planning a “smart home”, where lighting can be controlled by voice commands or clapping your hands.

Dimmers can be divided according to the type of lamps they control:

  1. The simplest devices are used for incandescent and halogen lamps, which operate on a voltage of 220 V. Everything is simple here - the voltage changes and the glow power of the filament is adjusted.
  2. The circuit for halogen lamps operating on a voltage of 12 V or 24 V must have a step-down transformer. When this is not possible, then choose a regulator for the type of transformer used (they have a special marking - C for electronic, RL for winding).
  3. LED lamps require the installation of dimmers with pulse modulation of the current frequency.

Energy-saving and fluorescent lamps are difficult to regulate. Experts generally do not recommend doing this. If you really need to control such light bulbs, then include an electronic starter in the dimmer circuit.

For more information about dimming different types of lamps, watch this video:

Well, we made an attempt to get acquainted with such a light regulator as a dimmer. We hope that now you more or less understand what it is and what the principle of operation is. Regarding connection diagrams, dimmers are installed in a circuit either instead of a switch or in series with it. By the way, if you have been good with electronics since the first grade, then making a dimmer with your own hands will not be difficult for you.

Good afternoon, dear Beauties!

I'm with you again, Oksana Zubkova:)

And today I want to tell you about the amazing power of not a miracle pill or an expensive procedure. And not about overseas SUPERed. Today we will talk about... simple cabbage :) But which is by no means simple. And it exists in Nature for the total protection of a Woman’s health and the natural balance of her hormones. It’s this STRONG cabbage we’ll talk about today.

It has been proven that women are almost several times more susceptible to various autoimmune diseases than men. The whole point is that the level of estrogen hormones directly affects the strength or weakness of our immunity. Immune cells typically have estrogen receptors, and it is these hormones that stimulate them to produce antibodies in the event of a threat to the health of the body.

If you observe yourself

- fluid retention
- premenstrual syndrome
- heavy or irregular periods
- breast enlargement or painful sensitivity
- breast cysts and ovarian cysts
- migraines and headaches
- hair loss, enlarged pores on the face
- bulging belly
– endometriosis, fibroids, problems with conception
- infertility
- difficulties with losing weight
- prostate problems, beer belly, breast growth, decreased libido in men...

Then know that the reason 90% hormonal problems modern man are PSEUDOestrogens - substances made by human hands, which, when entering our body, are recognized by it as its own hormones, estrogens.

PSEUDOestrogens, or “false” estrogens - These are synthetic hormones that contain birth control pills, heavy metals in the air and in food, dry cleaning of things, most commercial cosmetics, hair dye, plastic, antibacterial soap, coffee, commercial meat, as well as “harmless” thrush (candida ). They are capable, even with minimal entry into the body, to increase the amount of estrogen several times, thus disrupting the delicate balance of hormones and tens, hundreds of times increasing the chances of developing cancer.

“What does cabbage have to do with it?” - you ask :) And despite the fact that Nature gives us a unique solution to all the above problems - without synthetic hormones, treatments, pills and the like. Just cabbage! And you can be sure that you will take control of the level of “bad” estrogens easily and quickly.

Not everyone will eat cabbage for breakfast, lunch and dinner... And besides, there is no cabbage in winter. What to do? The answer, as always, is simple. Extract the substance DIM from cabbage, put it in a useful capsule and drink it with a glass of water.


DIM – di-indole methane
is an extract from cabbage plants that has the unique ability to remove PSEUDOestrogens from the body, thus providing your insurance for healthy hormones, protection against cancer and a strong immune system.

DIM makes your body slim, reducing the percentage of body fat, and gives you bright and beautiful sex, because it improves the functioning of not only your hormones, but also regulates the health of the prostate in Men.

DIM – Hormonal pill from Nature!

DIM is found in cruciferous vegetables, including kale, cauliflower, Brussels sprouts, savoy, red cabbage, kohlrabi, broccoli and other similar green vegetables.

Bioactive DIM in addition, this is the most natural way to improve the functioning of your hormones and bring your weight back to normal.

But that is not all! Substance found in red flowers - sulforaphane – is an oncoprotector that can suppress cancer cells and even promote their self-destruction. Sulforaphane also activates the restoration of proteins in cells damaged by malignant neoplasms and helps protect the body from the effects of carcinogens and free radicals. Numerous studies have proven its effectiveness in the treatment of breast cancer.

That's why DIM dietary supplement– your best, 100% natural protection against cancer!

The last chords to talk about are diminished and augmented.

Diminished chords are written either as "dim" or sometimes with a circle (Cdim or Co).

A dim chords are made up of the following notes:

1st, minor 3rd, diminished 5th, double flat 7th (double flat - for those who understand)

(a double flat 7th is the same note as a major 6th, but in music theory it's usually written as a double flat 7th and don't ask why!)

Adim would then look like: A, C, Eb, Gb

Note that the intervals between successive notes in a dim chord are ALL minor thirds.

This means that if you build a dim chord for C, you will get the same notes as for Adim.

In other words, Adim = Cdim = Ebdim = Gbdim = A+C+Eb+Gb So when you play a dim chord, moving it three frets up or down will give you the same chord!

There is also a chord called a half diminished chord or diminished 7. I usually write it something like E7-5 - another name for the same chord. It is very useful to know different names for the same chord.

The difference between it and the “regular” dim chord is that the 7th in this chord is simply flat, and not double flat (by the way, that’s why it’s called half-diminished).

It consists of the following steps: 1st, minor 3rd, minor 5th, minor 7th

An augmented chord is composed of the following notes:

1st, major 3rd, augmented 5th

So A aug looks like this: A C# F
(intervals between adjacent notes are major thirds - i.e. 4 semitones)

They are usually written as "A aug" or "A+" or "A+5".

Hello, dear readers. In today's article we will look at how to use a diminished chord in harmony, as well as what chords can be replaced with it.

We talked about the diminished chord in the article about seventh chords - this is a seventh chord, that is, it consists of four sounds. Why is it smaller? - read about this in the article. How to use this chord in harmony was discussed in the article. In fact, there are a lot of applications - we also replaced, for example, the G7 dominant seventh chord with diminished chords. You also know about the interesting features of these harmonies, which significantly expand the scope of their application on the guitar neck from the article.

Today we will learn something else interesting that can also be used.

Let's imagine that we have harmony and it contains, as usual, tonic - subdominant - dominant. And one of our chords is a major (or a major seventh chord) or even two, it doesn’t matter. For example, the tonic is C-maj, the subdominant is F-maj and the dominant is G7. By the way, do you remember how to replace each of these chords, using the features we described in the article?

We will consider the opportunity to diversify the major chord type today. Sometimes they use a combination of a diminished chord and a major; C-maj is alternated with a C-sharp-diminished - it sounds interesting. We can also play C#dim instead of C-maj, that is, they are interchangeable.

This way we can change the sound of the harmony as always. However, how did we come to the conclusion that these chords are interchangeable? What do they have in common? This is where the fun comes in. This is very similar to what we wrote in the article - where about the tonality of the third degree of kinship. True, in that article we simply talked about them, but did not consider how this happens, now we will do it.

How can we explain this? In fact, you may yourself come to the conclusion that C-maj and C#dim are related chords and can be changed with each other. To do this, you need to perform some manipulations - find the mediant Em from Cmaj.

rice. 1

Then turn Em into Em6 and change the bass note (tonic) to A (as we did in the article).

rice. 2

And then we change the note A in the resulting A7 to A-sharp, getting C#dim (C-sharp-diminished).

rice. 3

It turned out that the chords Cmaj and C#dim are to some extent equal to each other and therefore can interact in harmony, or even replace each other.

rice. 4

In this simple way (in about three steps) we can find replacements for major chords (not only for major major, but also for ordinary triads and dominant seventh chords) and use them successfully. The diminished chord in our case is good to take in the middle of the composition when you are developing it, because it sounds tense and it is very good to move from it into chords that have a softer and more stable sound.

A variable is a container in which VBA stores data. In more detail, it’s like a box in which you can put something for storage and then take it out as needed. Only in this case, we store a number, string or other data in a variable, which we can then extract from it and use in the code as needed.

What is the variable for? To store a value and apply it later at any time. For example, the amount is written in cell A1, and clicking the button starts updating the report. After updating the report, the amount in A1 will change. It is necessary to check the amount before the update with the amount after and, depending on this, take some action. The variable will just allow you to remember the value of the cell before it is updated and use exactly this value after the update.

Requirements for variables:

You can use letter and number symbols as variable names, but the first letter in a variable name must always be a letter. The use of periods, commas, spaces and other punctuation marks other than underscores is not permitted. The name length must not exceed 254 characters. You also cannot use reserved constants of the VBA editor as names for variables. (for example Sub, Msgbox, ubound, Date, etc.). Also, the case of letters is not important for variables.

Now let's look at the main data types declared in VBA that can be stored in variables:

Data type Occupies a byte in memory Value limits
Byte 1 Integers from 0 before 255
Boolean 2 True or False
Integer 2 Integers from ( -32768 ) before 32767
Long 4 Integers from ( -2147483648 ) before 2147483647
Single 4 From ( –3.402823E+38) before ( –1.401298E-45) and from 1.401298E-45 before 3.402823E+38
Double 8 From ±1.79769313486232E+308 before ±4.94065645841247E-324
Decimal 12 From ±79228162514264337593543950335 no decimal places before ±7.9228162514264337593543950335 with 28 decimal places
Currency 8 From ( –922337203685477.5808 ) before 922337203685477.5807
Date 8 From 01.01.100 before 31.12.9999 (not to be confused with dates in Excel - 01/01/1900 to 12/31/2078)
String 1 From 0 before 65400 characters for fixed strings and just over 2 billion for variable length strings
Object 4 Any object
Array Determined by the number and size of elements -
Variant from 16 Any of the built-in data types

As you can see from the table, Variant takes up the most memory. Moreover, this is if it stores numerical data. If such a variable stores data of the string type (text), then the size of the occupied memory will be measured starting from 22 bytes + the length of the string stored in the variable. The more memory a variable takes up, the longer it takes to initialize in memory and the slower the code will execute. This is why it is important to explicitly set the type of data stored in a variable - this is called declare a variable.

The Decimal data type is no longer used, so declaring a variable of this type in VBA will not work - such an attempt will result in a syntax error. To work with data of the Decimal type, the variable must initially be declared as a Variant or without a type at all (for example, Dim a), because The Variant data type is the default in VBA and accepts any data type.

You can also assign other data types to variables that are not in the table above - these are types that are supported by the object model of the applications to which VBA is “connected”. For example, if you enter VBA from Excel, the Excel object model type library is enabled by default and many types of this object model become available for variables. Many of them are familiar to everyone: Workbook, Worksheet, Range, Cells, Chart, etc. Those. These are books, sheets, cells, charts. There are many types, for almost every object and collection. There is no point in discussing everything here. I can just give you a couple of lines of code:

Dim rRange as Range Set rRange = Range("A1") "assigned a reference to cell A1 of the current sheet

Variable declarations are described in detail below.
You can read more about accessing ranges from VBA in this article: How to access a range from VBA

How to declare variables
In fact, everything is very simple. This is done using the scope operators: Dim, Public, Static and the assignment operator As. The most common operator is Dim. Let's take it as an example. Declaration syntax:

[scope operator] Variable_name As [data type]

A very common mistake when declaring variables made by beginners learning VBA:

Dim MyVar1, MyVar2, MyVar3 As Integer

Dim MyVar1, MyVar2, MyVar3 As Integer

It seems that based on logic, all variables are assigned the Integer data type. But this is an erroneous judgment. The Integer type is assigned only to the last variable to which it is “bound” by the As operator - MyVar3. All other variables are of the Variant data type. Those. if you do not explicitly specify the type of stored data for the variable (i.e. do not specify a data type for it), then VBA itself assigns the Variant data type to such a variable, because it can store any type of data. And this is what a correct data type assignment looks like:

Dim MyVar1%, MyVar2%, MyVar3%

There are only six types that can be declared with a similar method:
! - Single
# - Double
$ - String
% - Integer
& - Long
@ - Currency
What you should pay attention to when declaring variables in this way: there should be no spaces between the variable name and the type sign.
I personally prefer to use the first method, i.e. full type indication. It's more readable and understandable. But these are my preferences and in your codes you have the right to use a method convenient for you - there will be no mistakes.

Now let's look at the scope operators (Dim, Public and Static):

  • Dim - this operator is used to declare a variable, the value of which will be stored only in the procedure within which this variable is declared. When a procedure is launched, such a variable is initialized in memory. You can use its value within only this procedure, and upon completion of the procedure, the variable is unloaded from memory (reset to zero) and the data on it is lost. A variable declared in this way is also called local variable. However, using this operator, you can declare a variable that will be available in any procedure in the module. It is necessary to declare a variable outside the procedure - in the declaration area (read as the first line in the module, after the declaration lines of the type - Option Explicit). Then the value of the variable will be available in any procedure only of the module in which this variable was declared. Such variables are called module level variables.
  • Static - this operator is used to declare a variable whose value is intended to be used within a procedure, but without losing the value of this variable upon completion of the procedure. Variables of this type are usually used as cumulative counters. Such a variable is initialized in memory the first time the procedure in which it is declared is executed. Upon completion of the procedure, the data for the variable is not unloaded from memory, but it is not available in other procedures. As soon as you run the procedure with this variable again, the data for such a variable will be available in the form in which it was before the procedure was completed. Such a variable is unloaded from memory only after the project is closed. (books with code). In common parlance, such variables are more often called global(possibly due to the fact that previously such variables were declared using the Global operator, which is now obsolete and not used)
  • Public - this operator is used to declare a variable whose value will be stored in any project procedure. A variable declared in this way must be declared outside the procedure - in the declaration area. Such a variable is loaded into memory when the project is loaded (when opening the book) and stores the value until the project is unloaded (closing the book). You can use it in any module and any project procedure. Important: It is necessary to declare a variable in this way strictly in a standard module. Such variables are called project level variables.
    For a better understanding of where and how to declare project-level variables, two small examples.
    Wrong ad

    Option Explicit Sub main() Public MyVariable As String MyVariable = "Global variable" "show the current value of the variable MsgBox MyVariable "try to change the value of the variable Call sub_main "show the changed value of the variable MsgBox MyVariable End Sub "additional procedure for changing the value of the Sub variable ChangeMyVariable() MyVariable = "Changed its value" End Sub

    variables will not be visible in all modules of all procedures and functions of the project because:
    1. The Public operator is not allowed inside a procedure (between Sub and End Sub), so VBA will definitely throw an error when trying to execute such a procedure - Invalid Attribute in Sub or Function.
    2. Even if Public is replaced with Dim, it will already be a procedure-level variable and will not be available for other procedures.
    3. Because the declaration is incorrect - the second procedure (ChangeMyVariable) does not know anything about the MyVariable variable and, naturally, will not be able to change it.
    Correct announcement

    "above global variables and constants there can only be declarations: Option Explicit "forced declaration of variables Option Base 1 "the lower bound of declared arrays starts at 1 Option Compare Text "case-insensitive text comparison "global variable - first line, above all procedures Public MyVariable As String "further procedures and functions Sub main() MyVariable = "Global variable" "show the current value of the variable MsgBox MyVariable, vbInformation, "www.site" "trying to change the value of a variable Call ChangeMyVariable "show the changed value of the variable MsgBox MyVariable, vbInformation, "www.site" End Sub "additional procedure for changing the value of a variable Sub ChangeMyVariable() MyVariable = "They changed its meaning" End Sub

    "Only declarations can be above global variables and constants: Option Explicit "forced declaration of variables Option Base 1 "lower limit of declared arrays starts at 1 Option Compare Text "case-insensitive text comparison "global variable - first line, above all procedures Public MyVariable As String "further procedures and functions Sub main() MyVariable = "Global variable" "showing the current value of the variable MsgBox MyVariable, vbInformation, "www.site" "trying to change the value of the variable Call ChangeMyVariable "showing the changed value of the variable MsgBox MyVariable, vbInformation, "www ..procedure for changing the value of a variable Sub ChangeMyVariable() MyVariable = "Changed its value" End Sub

  • Scope operators can also be applied to procedures. There is one more scope operator available for procedures - Private. A procedure declared in this way is accessible only from the module in which it is written and such a procedure is not visible in the dialog box for calling macros( Alt+F8)

How to correctly name a variable:

"What's the hardest thing about being a programmer? It's coming up with names for variables." :-) But coming up with a variable name is also not so easy. You can, of course, give them names like: a, d, f, x, y etc. (I sometimes do this myself, but either in simple codes or for special obfuscation of the code). But it’s worth thinking about: how will you manage them in a large code? Line 10 code will still tolerate such names, but for larger projects, I would not recommend operating with such variables in them. You yourself will get confused about which variable is declared and what type of data it can store and what value is assigned to it. Therefore, it is best to give your variables meaningful names and follow variable naming conventions. What kind of agreement? It's very simple: a prefix is ​​placed before the main name of the variable, indicating the type of data that we intend to store in this variable. I have already talked about the available data types above. Below is an example table of prefix correspondence to data types:

Prefix Type of data stored
b Boolean
bt Byte
i Integer
l Long
s Single
d Double
c Currency
dt Date
str String
obj Object
v Variant

Personally, I remade it a little for myself, because... Some of the notations seem sparse to me. For example, I denote Double as dbl, and Single as sgl. This seems more clear to me.

What is another advantage of explicitly specifying the data prefix. VBA has operators such as Def, which can be used to specify the default data type for variables whose first letter of name falls within the range specified in the operator. For example:

DefBool B-C Sub test() Dim bCheck, cCheck End Sub

But I believe that one letter for one type is quite enough. You can specify several Def operators at once.

DefBool B DefStr S Sub test() Dim bCheck, sCheck End Sub

DefBool B DefStr S Sub test() Dim bCheck, sCheck End Sub

Below is a complete list of type operators and the data that each specifies:
DefBool- Sets the type to Boolean
DefByte- Sets the Byte type
DefCur- Sets the Currency type
DefDate- Sets the Date type
DefDbl- Sets the Double type
DefInt- Sets the type to Integer
DefLng- Sets the Long type
DefObj- Specifies the Object type
DefSng- Sets the Single type
DefStr- Specifies the String type
DefVar- Specifies the Variant type
By default, VBA uses the DefVar statement for all variables.

Well, an important point is the directly meaningful name of the variable. The variable name should roughly reflect what will be stored in it. For example, you are creating a report and you need to declare two variables: one is the name of the sheet, the other is the name of the workbook. You could do it like this: str1, str2. In short, great. But if you think about it, how can you understand which of these variables stores what? No way. You need to look through the code and remember which variable was assigned which value. Not exactly convenient, right? What if you set the names like this: strBookName, strSheetName, then it seems to be more clear what we will store in them. This is convenient not only for you when working with code, but also for other people who may use your code in the future. It will be more convenient for them to read the code if it is formatted correctly and the variables are named meaningfully. And you shouldn’t skimp on the length of the name - the name should be understandable. Without fanaticism, of course :-). Although VBA allows us to create variables up to 254 characters long, it is just as inconvenient to read such a variable as with one character. But here everything depends on your preferences and imagination.
Small addition: It’s better to get used to naming variables in the Latin alphabet (i.e. English alphabet), because For VBA, English is the "native" language and it is better to use it.

A small example of using variables in codes:

Sub main() "we declare variables with the assignment of specific types"As String - text "As Long is an integer Dim sAddress As String , sNewAddress As String , sShName As String Dim lRow As Long Dim rRange as Range "assigned variable type cell/range "assigned the rRange variable a reference to the currently selected cell Set rRange = Selection "change the selection - select cell D9 Range("D9").Select "assign the variable the address of the selected cells sAddress = Selection.Address "assign variable lRow the value of the first row of the selected area lRow = Selection.Row "show message MsgBox "Address of the selected area: "& sAddress, vbInformation, "www.site" MsgBox "First line number: "& lRow, vbInformation, "www.site" "assign to another variable the value of the address of cell A1 sNewAddress = "A1" "select the cell specified by the sNewAddres variable Range(sNewAddress).Select MsgBox "Address of the selected area: "& sNewAddress, vbInformation, "www.site" "select the initially selected cell using the rRange variable rRange.Select MsgBox "Address of the selected area: "& rRange.Address, vbInformation, "www.site" "set the value of the variable sShName = "excel-vba" "rename the active sheet to the name specified by the variable ActiveSheet.Name = sShName End Sub

Sub main() "declare variables with the assignment of specific types "As String - text "As Long - integer Dim sAddress As String, sNewAddress As String, sShName As String Dim lRow As Long Dim rRange as Range "assigned the cell/range type to the variable " assigned the variable rRange a link to the current selected cell Set rRange = Selection "change the selection - select cell D9 Range("D9").Select "assign the variable the address of the selected cells sAddress = Selection.Address "assign the variable lRow the value of the first row of the selected area lRow = Selection .Row "show the message MsgBox "Address of the selected area: " & sAddress, vbInformation, "www..site" "assign the value of the address of cell A1 to another variable sNewAddress = "A1" "select the cell specified by the variable sNewAddres Range(sNewAddress).Select MsgBox "Address of the selected area: " & sNewAddress, vbInformation, "www.site" "select the initially selected cell using the rRange variable rRange.Select MsgBox "Address of the selected area: " & rRange.Address, vbInformation, "www.site" "set the value variable sShName = "excel-vba" "rename the active sheet to the name specified by the variable ActiveSheet.Name = sShName End Sub

The article will help you see step-by-step execution of this code: Catching errors and debugging VBA code
Important! If a variable is assigned a cell reference (Set var = Range("A1")), then accessing the variable is identical to accessing cell A1 itself whenever this happens. This assignment does not remember the properties of the cell before or after - the variable stores a reference to a specific cell and access is available exclusively to the properties of the cell at the current moment. To remember the value, color of a cell, or even the address (as well as other properties) before changing the cell and apply them even after changing/moving the cell itself, you need to remember exactly the properties of the cell in variables:

Sub main() Dim val, l_InteriorColor As Long , l_FontColor As Long Dim rRange As Range "assigned variable type cell/range "assigned the rRange variable a reference to the active cell Set rRange = ActiveCell "remember the properties of the cell val = rRange.Value "value l_InteriorColor = rRange.Interior.Color"цвет заливки l_FontColor = rRange.Font.Color "цвет шрифта !} "copy another cell and paste it in place of the active one ActiveSheet.Range("D1" ).Copy rRange "check that rRange now has completely different properties - like D1 "rRange fill color: " "Font color rRange: "& rRange.Font.Color & vbNewLine, vbInformation, "www.site" "assign properties from those stored in variables rRange.Value = val "value rRange.Interior.Color = l_InteriorColor "fill color rRange.Font.Color = l_FontColor "font color "check that rRange parameters are returned before copying MsgBox "rRange Value: " & rRange.Value & vbNewLine & _ "rRange fill color: "& rRange.Interior.Color & vbNewLine & _ "Font color rRange: "& rRange.Font.Color & vbNewLine, vbInformation, "www.site" End Sub

Sub main() Dim val, l_InteriorColor As Long, l_FontColor As Long Dim rRange As Range "assigned a cell/range type to the variable "assigned a reference to the active cell to the rRange variable Set rRange = ActiveCell "remember the cell properties val = rRange.Value "(!LANG :l_InteriorColor value = rRange.Interior.Color"цвет заливки l_FontColor = rRange.Font.Color "цвет шрифта "копируем другую ячейку и вставляем на место активной ActiveSheet.Range("D1").Copy rRange "проверяем, что rRange теперь имеет совершенно другие свойста - как у D1 MsgBox "Значение rRange: " & rRange.Value & vbNewLine & _ "Цвет заливки rRange: " & rRange.Interior.Color & vbNewLine & _ "Цвет шрифта rRange: " & rRange.Font.Color & vbNewLine, vbInformation, "www..Value = val "значение rRange.Interior.Color = l_InteriorColor "цвет заливки rRange.Font.Color = l_FontColor "цвет шрифта "проверяем, что rRange возвращены параметры до копирования MsgBox "Значение rRange: " & rRange.Value & vbNewLine & _ "Цвет заливки rRange: " & rRange.Interior.Color & vbNewLine & _ "Цвет шрифта rRange: " & rRange.Font.Color & vbNewLine, vbInformation, "www.сайт" End Sub!}

This also applies to all other objects. Those. those variables whose values ​​are assigned through the Set statement.

Constants
There is also another type of “variables” - constants. This is the same variable, only (as its name suggests) it cannot be changed during code execution, because is a constant value and its value is assigned only once - before executing the code.

Const sMyConst As String = "My program name"

Const sMyConst As String = "My program name"

Constants can be assigned the same types of data as variables. For additional scope/life of constants, only Public is used. If the scope is not specified, then the constant will be accessible only from the module in which it is declared. Here I would like to draw your attention to the fact that Dim is no longer used, because Dim is an identifier for variables only. A couple of important differences between declaring constants and declaring variables:

  • When declaring a constant, you must explicitly indicate that it is a constant using the Const keyword
  • immediately at the time of declaration, you must assign the value to the constant: = "The name of my program"

In all other respects, the declaration and use of constants is identical to the declaration of variables. Let me briefly give a couple of examples.
If the constant is declared inside a procedure:

Sub TestConst() Const sMyConst As String = "My program name" MsgBox sMyConst "show a message with the program name End Sub Sub TestConst2() MsgBox sMyConst "will cause an error Variable not defined End Sub

To use one constant in all procedures of a project (book), you must declare it as Public.

mob_info