excel vba - Use of symbol # (hash) in VBA Macro -
what meaning of use of # symbol in excel vba?
it used this:
= b /100# i don't understand significance of # after 100?
the type-declaration character double number sign (#). called hash
other type declaration characters are:
- integer %
- long &
- currency @
- single !
- double #
- string $
don't understand significance of # here.
it implies when expression evaluated, number in front of type declaration character treated specific data type instead of variant.
see example, same.
sub sample1() dim a# = 1.2 debug.print end sub sub sample2() dim double = 1.2 debug.print end sub edit
let me explain little more in detail.
consider 2 procedures
sub sample1() dim double, b integer b = 32767 = b * 100 debug.print end sub sub sample2() dim double, b integer b = 32767 = b * 100# debug.print end sub question: 1 of them fail. can guess one?
ans: 1st procedure sub sample1() fail.
reason:
in sample2, when b * 100# result of calculation of type double. since within limits of double, calculation succeeds , result assigned variable a.
now in sample1, when b * 100 result of calculation of type integer, since both operands of type integer. result of calculation exceeds limits of integer storage. result error out.
hope helps :)
Comments
Post a Comment