Vba: what is 97.45 * 1 # =?

some_integer = 97.45 * 1#

What do these designations mean? what will some_integer =?

+4
source share
5 answers

Just to expand on what everyone else has added ... As already mentioned, the hash tag (#) is a type declaration symbol (TDC) and forces the literal "1" to use the Double type. This data type conversion belongs to a class of transformations called "Explicit Conversions". Also in this class are Casts (such as CStr (), CLng (), etc.).

, . Implicit Conversion - , VBA . ( Dim j As Long), . , , ( " " ).

, , :

, . . 1 . 2 - . .

, , . . , Literal . :

  • , , .
  • , Double.
  • , -32,767 32,767 (), Integer.
  • , -2,147,483,647 2,147,483,647 (), -32,767 32,767 Long.
  • , , -2147,483,647 2,147,483,647 Double.
  • .

, , , . . DataType DataTypes . DataType :  1. - DataType Variant VBA, DataType , .  2. , .  3. , DateType , DataType ( "" ).

3. (, 500 400), (, 500 * 400), (200 000) , DateType ( ). . 500 400 , , (, 500 400). , , (Long), , .

, 2, ( , ). Double . , , , .

, , , .

Micro-Optimization, , . , Double Double. , . , , , .


:

Type Declaration Character Data Type
          %                 Integer
          &                 Long
          !                 Single
          #                 Double
          $                 String
          @                 Currency 

: Dim ( - ). : Dim s As String Dim s$ String . , TDC. , Public Function MyFunc()& Public Function MyFunc() As Long.


Function    Return Type
CBool       Boolean
CByte       Byte
CCur        Currency 
CDate       Date 
CDbl        Double 
CDec        Decimal
CInt        Integer
CLng        Long
CSng        Single
CStr        String
CVar        Variant
+14

some_integer 97.45.

1 , . (E.G 1 , 1 )

some_integer = 97.45 * 1# some_integer = 97.45 * 1.00

+9

1# "1 ". , some_integer , 97 (, , , ).

INFO: ( VBA)

+6

1# , 1 .

I doubt that would affect this calculation. The calculation will still give 97.45 if 1 was not decorated and, therefore, processed as an integer. And when the result of the calculation is assigned to an integer some_integer, it will be equal to 97.

Sub Macro1()
    Dim i As Integer
    i = 97.45 * 1#
    MsgBox (i) 'Shows 97
End Sub
+2
source

A #in VB means "type Double."

So there some_integerwill be 97.

+2
source

Source: https://habr.com/ru/post/1755802/


All Articles