I have seen that many people write code like this:
Can't they simply write it like this:HTML Code:Dim i as long
...
i = i + 1&
What is the benefit of that and sign after the number?HTML Code:Dim i as long
...
i = i + 1
thanks,
Printable View
I have seen that many people write code like this:
Can't they simply write it like this:HTML Code:Dim i as long
...
i = i + 1&
What is the benefit of that and sign after the number?HTML Code:Dim i as long
...
i = i + 1
thanks,
By default every numeric literal in VB6 is an Integer Type, so if you want to explicitly specify a literal number as being a Long Type you suffix it with an &.
Also:
Code:Debug.Print TypeName(1) '<-- use % here and the IDE collapses it away as the default type.
Debug.Print TypeName(1&)
Debug.Print TypeName(1!)
Debug.Print TypeName(1#)
Debug.Print TypeName(1@)
Debug.Print TypeName(1.1!)
Debug.Print TypeName(1.1) '<-- use # here and the IDE collapses it away as the default type.
Debug.Print TypeName(1.1@)
There are a number of ways where typing a numeric literal explicitly can make a difference. For example it can be a hint to the compiler not to reduce the precision of an expression. Or another example, when calling a Declared DLL entrypoint it can be used with ByVal to tell the compiler what type of data to use as an argument (what to put on the stack):Code:Integer
Long
Single
Double
Currency
Single
Double
Currency
Quote:
SomeEntry This, That, ByVal 0&