Results 1 to 3 of 3

Thread: Why use an and sign?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2010
    Posts
    844

    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,

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    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 &.

  3. #3
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Why use an and sign?

    Also:
    Code:
        Debug.Print TypeName(1) '<-- use &#37; 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
  •  



Click Here to Expand Forum to Full Width