-
Nov 25th, 2005, 07:56 PM
#1
Classic VB - What Are #, $, etc.?
The symbols are "shortcuts" for several of the Visual Basic data types. # is the shortcut for Double, so
is the same as
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 05:38 PM.
-
Nov 25th, 2005, 11:56 PM
#2
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 05:38 PM.
-
Nov 26th, 2005, 08:29 PM
#3
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:
Private Sub Command1_Click()
Dim var1%, var2&, var3#, var4!, var5@, var6$
Debug.Print "var1: " & TypeName(var1)
Debug.Print "var2: " & TypeName(var2)
Debug.Print "var3: " & TypeName(var3)
Debug.Print "var4: " & TypeName(var4)
Debug.Print "var5: " & TypeName(var5)
Debug.Print "var6: " & TypeName(var6)
End Sub
Last edited by si_the_geek; Nov 27th, 2005 at 05: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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|