I am working on a project for a customer and the previous developer had used shrotcuts like ! , % , $, # when declaring their variables. I have never used these before and cannot find any documentation on these. Has anyone ever used them before
These are tags added to the ends of variable names (they can also be used on method names) to specify the type of the variable.
Believe it or not, they still exist in VB.NET, but I think every standard you'll ever come across would say to avoid them.
(We call them "ancient type specifiers" at Tangible...).
Some people (I've only met one) like them since instead of typing "Dim someString As String", you can save a few keystrokes by typing "Dim someString$" (see Dave299's reply for the correspondence of the specifiers and types).
VB.NET still cries out for more purging of these incredibly ugly 'features' (ditto for 'REM').
If it is recommended that we all stop using them then I will continue to use the Convert CLASS.
Code Block
Dim myNum As Object
myNum = 8.0!
'Single.
myNum = 9%
'Integer.
myNum = 10&
'Long.
myNum = 11.0#
'Double.
'Why was F decided to be used for a sin-gle Why not G as the 1st letter of the 2nd syllable
'Why was R decided to be used for a dou-ble Why not B as the 1st letter of the 2nd syllable
myNum = 2D
'Decimal.
myNum = 3.0F
'Single.
myNum = 4I
'Integer.
myNum = 4UI
'Uinteger.
myNum = 5L
'Long.
myNum = 5UL
'ULong.
myNum = 6.0R
'Double.
myNum = 7S
'Short.
myNum = 7US
'UShort.
I am guessing that Microsoft will keep these in Visual Studio to maintain some "backwards compatability" with older code
It's the symbol postfixes that are there for backwards compatibility (e.g., !, %, $, ...), not the letter postfixes (also, the symbol postfixes can also be used in variable declarations instead of specifying the type explicitly).
Variable Declaration Shortcuts
OlegGo
In VB5 they translated as follows:
! - Single
% - Integer
# - Double
& - Long
$ - String
@ - Currency
milkshake
tvenhaus
These are tags added to the ends of variable names (they can also be used on method names) to specify the type of the variable.
Believe it or not, they still exist in VB.NET, but I think every standard you'll ever come across would say to avoid them.
(We call them "ancient type specifiers" at Tangible...).
Some people (I've only met one) like them since instead of typing "Dim someString As String", you can save a few keystrokes by typing "Dim someString$" (see Dave299's reply for the correspondence of the specifiers and types).
VB.NET still cries out for more purging of these incredibly ugly 'features' (ditto for 'REM').
kokitsune
Thank you,
That might very well explain why I am having issues in .NET..
Neotech
Hi,
These are also available in VB.Net.
If it is recommended that we all stop using them then I will continue to use the Convert CLASS.
Dim myNum As Object
myNum = 8.0!
'Single.myNum = 9%
'Integer.myNum = 10&
'Long.myNum = 11.0#
'Double.
'Why was F decided to be used for a sin-gle Why not G as the 1st letter of the 2nd syllable 'Why was R decided to be used for a dou-ble Why not B as the 1st letter of the 2nd syllablemyNum = 2D
'Decimal.myNum = 3.0F
'Single.myNum = 4I
'Integer.myNum = 4UI
'Uinteger.myNum = 5L
'Long.myNum = 5UL
'ULong.myNum = 6.0R
'Double.myNum = 7S
'Short.myNum = 7US
'UShort.I am guessing that Microsoft will keep these in Visual Studio to maintain some "backwards compatability" with older code
Regards,
John
Mary-Rosey
Seppe001
It's the symbol postfixes that are there for backwards compatibility (e.g., !, %, $, ...), not the letter postfixes (also, the symbol postfixes can also be used in variable declarations instead of specifying the type explicitly).