|
-
Feb 4th, 2012, 02:46 AM
#1
Thread Starter
Fanatic Member
Why use an and sign?
I have seen that many people write code like this:
HTML Code:
Dim i as long
...
i = i + 1&
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?
thanks,
-
Feb 4th, 2012, 02:54 AM
#2
Re: Why use an and sign?
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 &.
-
Feb 4th, 2012, 06:25 AM
#3
Re: Why use an and sign?
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@)
Code:
Integer
Long
Single
Double
Currency
Single
Double
Currency
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):
SomeEntry This, That, ByVal 0&
Last edited by dilettante; Feb 4th, 2012 at 06:29 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|