Classic VB - What Are #, $, etc.?-VBForums
Results 1 to 3 of 3

Thread: Classic VB - What Are #, $, etc.?

  1. #1

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    32,844

    Classic VB - What Are #, $, etc.?

    The symbols are "shortcuts" for several of the Visual Basic data types. # is the shortcut for Double, so

    VB Code:
    1. Dim MyVar#
    is the same as
    VB Code:
    1. Dim MyVar As Double

    Similarly:
    ! = Single
    & = Long
    @ =Currency
    % = Integer
    $ = String

    Note: Using the shortcuts is not recommended since they take away from the readability and self-documenting features of Visual Basic.
    Last edited by si_the_geek; Nov 27th, 2005 at 04:38 PM.

  2. #2
    Moderator
    Join Date
    Jan 2005
    Location
    Sydney
    Posts
    13,621

    Re: Classic VB - What Are #, $, etc.?

    In addition, the type symbols can be used to differentiate between functions of the same name but different return types. For example, the VB runtime function Trim(), which removes whitespace from the left and right of a string, returns a Variant containing a String, but the function Trim$() returns a String directly. Since you should always try not to use Variants, as they are large and slow, using the Trim$() function will be more efficient than Trim() as there is no need to convert to and from the Variant type.

    Other similar functions are Left()/Left$(), Right()/Right$(), Mid()/Mid$(), and many other string functions.

    Note that you cannot create two functions with the same name but different types, even though there are examples of it in the VB runtime library.
    Last edited by si_the_geek; Nov 27th, 2005 at 04:38 PM.

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,135

    Re: Classic VB - What Are #, $, etc.?

    In addition for those that wonder how to identify via code variable's type (especially those that were declared with type shortcuts) here is a sample:
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim var1%, var2&, var3#, var4!, var5@, var6$
    3.  
    4.     Debug.Print "var1: " & TypeName(var1)
    5.     Debug.Print "var2: " & TypeName(var2)
    6.     Debug.Print "var3: " & TypeName(var3)
    7.     Debug.Print "var4: " & TypeName(var4)
    8.     Debug.Print "var5: " & TypeName(var5)
    9.     Debug.Print "var6: " & TypeName(var6)
    10.  
    11. End Sub
    Last edited by si_the_geek; Nov 27th, 2005 at 04:38 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.