With which the declaration or definition of the memory variable is assigned
The purpose of variables is to store and process values. You can write texts e.g. B. put together, you can calculate with numbers. To do this, the software must recognize whether a variable contains text or a number. So one expects z. B. that “lunch” and “eat” are combined to “lunch”, but “1” and “2” should result in “3” and not “12”. If we want it differently (i.e. an interpretation as text), we have to be able to tell the program specifically. Different computer programs provide different methods for this. In this regard, VBA is a so-called typed programming language. This means that every variable has a specific Data type it is determined from the outset what kind of values can be stored in a variable.
|a + b =?|
Sub HalloDu () Dim myText As String myText = "Hello World" Debug.Print myText End Sub
We already knew this example, but the variable declaration has been added so that the variable can only save text. The data type follows the keyword. As soon as you have typed, IntelliSense provides a fairly long selection list. The list varies depending on the application in which VBA is currently running. If you know "your" application, a lot will look familiar here. But initially we are only interested in them VBA internal data types:
|Type||Range of values||Memory requirements||Initial value||example|
|Boolean||Yes / No values (True or False)||2 bytes||False||female = true|
|byte||Integers 0 to 255||1 byte||0||Age = 42|
|Integer||Integers -32,768 to 32,767||2 bytes||0||Year of construction = 1950|
|Long||Integers -2,147,483,648 to 2,147,483,647||4 bytes||0||Customer number = 23|
|LongLong ¹||Integers approximately ± 9 trillion||8 bytes||0||People =|
|Currency||scaled integers approx. ± 9 trillion, 4 decimal places||8 bytes||0||Euro = -47.11|
|single||Floating point number, single precision||4 bytes||0||rounded = 1.5|
|Double||Floating-point number, double precision||8 bytes||0||Result = 1.75|
|Date||Date (Jan 1, 100 to Dec 31, 9999) and time||8 bytes||30.12.1899 00:00||Today =|
|String||Texts||Number Character * 2||""||Info = "Hello world"|
|Object||depending on the object||4 bytes||Nothing||Set BMW = car|
|Variant||depending on the current content||differently||Empty||miscellaneous = -1|
¹ Only available on 64-bit systems
The decision for a data type depends on whether you want to save texts or numbers. There is also the syntax for texts of fixed length, e.g. B. if the string should always contain exactly one character. When it comes to numbers, a distinction is made between integers and floating point numbers. There are several data types for this (integers:, and. Floating point numbers: and). rather exists for reasons of compatibility and should no longer be used today. is internally an integer that is divided by 10000 and thus has 4 fixed decimal places. In contrast to "normal" floating point numbers, this is a very precise calculation method and is therefore particularly recommended in connection with amounts of money. -Variables can have any value. An instruction without a data type declares the variable as a variant.
As soon as a variable has been declared, it is assigned an initial value and storage space. Numeric variables are assigned the value 0, strings an empty string "". Fixed-length strings are assigned a character sequence consisting of the control character, as often as the string is long. A variant variable is given the special value, which indicates that it has not yet been assigned a value. You can also reassign it later in order to put it back into a “virginal state”. A variant can also contain the special value to indicate that the variable does not contain valid data.
-Variables are only addressed much later in the tutorial. It should only be mentioned here that the initial value is a special value to indicate that the variable does not refer to an object.
In practice it is seldom of interest how much memory space a variable consumes - unless you want e.g. B. save an entire database in variables at once. With and you can see why these data types can have a performance problem: their memory requirements change depending on the content of the variable. “Under the hood” the computer has to rearrange a lot in the memory when the content changes. In addition, VBA must also remember which data type the current value is to be interpreted as. While therefore in the environment z. B. from Microsoft Access the data type is frowned upon, some users of Microsoft Excel often used to use variables like in a non-typed script language.
- How scalable is Parse
- Which startups are offering winter internships in 2016?
- Exercise may cause a mild fever
- Find an online training course
- How to Buy Real Estate in India
- What does stand out mean?
- How agencies use G Suite
- What is the best stealth fighter right now
- Violinists ever use viola bows
- What did the 14th change originally guarantee?
- How common are earthquakes in Southern California
- Swami Vivekananda's original name was
- Which element has the smallest size
- What does Age of Learning
- Is it Safe to Eat Rare Hamburgers?
- How can I overcome a slight androphobia
- Why aren't there more nihilists
- Did the prison save your life?
- What causes neck lumps
- What is a god object in OOP
- Architecture changes our behavior
- What are the preventive measures for stakes
- Why are narcissists addicted to sex?
- Is tuberculosis considered dangerous