Excel VBA Pound and Colon Signs Meaning?

点点圈 提交于 2020-01-13 09:56:06

问题


I am trying to understand a vba function with the pound and colon symbol interspersed throughout it.

VBA function:

kn = 1#: pn = 1#:  y = 1#

I know the pound sign is used to declare a variable as a double in Excel VBA. However, it does not seem to make any sense in terms of the above line. What does the above function do?


回答1:


The colon (:) is a statement delimiter. It would be equivalent to a new line in VBA, or a semicolon in C (just to quote a random example). It allows you to write several instructions on a single line rather than going to a new line each time.

The pound (#) is a short-hand type specifier that forces your literals to be double, so basically 1# is almost equivalent to 1.0.




回答2:


****Here is a Cheat Sheet for DataTypes ****

Variable End with:

$ : String
% : Integer (Int32)
& : Long (Int64)
! : Single
# : Double
@ : Decimal

Start with:

&H : Hex
&O : Octal

Visual Studio .Net added Literal Types (reference)

Value End with: (For more complete list, refer the the reference)

S : Short (Int16)
I : Integer (Int32)
L : Long (Int64)
F : Single
R : Double
D : Decimal



回答3:


Building off Romain's response, kn = 1#: pn = 1#: y = 1# is equivalent to:

kn = 1#
pn = 1#
y = 1#


来源:https://stackoverflow.com/questions/7649101/excel-vba-pound-and-colon-signs-meaning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!