vba 有趣的符号#

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2829128/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 11:38:51  来源:igfitidea点击:

Funny notation with #

excelvbaexcel-vba

提问by l--''''''---------''''''''''''

what does this mean?

这是什么意思?

if CDbl(Trim(Range("M" & r).Text)) > 0# then...

what does the # do?? and what does cdbl do?

# 是做什么的??cdbl 有什么作用?

采纳答案by Gerhard Powell

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

****这是数据类型的备忘单****

Variable End with:

变量结尾为:

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

Start with:

从...开始:

&H : Hex
&O : Octal

Comparison between VB and VB.Net (reference)

VB和VB.Net的比较(参考

Visual Studio .Net added Literal Types (reference)

Visual Studio .Net 添加了文字类型(参考

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

Convert to:

转换成:

CBool(expression)
CByte(expression)
CCur(expression)
CDate(expression)
CDbl(expression)
CDec(expression)
CInt(expression)
CLng(expression)
CLngLng(expression) (Valid on 64-bit platforms only.)
CLngPtr(expression)
CSng(expression)
CStr(expression)
CVar(expression)

回答by BradC

CDbl()convert an expression to a Double:

CDbl()将表达式转换为 Double:

A data type that holds double-precision floating-point numbers as 64-bit numbers in the range -1.79769313486231E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values.

将双精度浮点数保存为 -1.79769313486231E308 到 -4.94065645841247E-324 范围内的 64 位数字的数据类型(对于负值);4.94065645841247E-324 到 1.79769313486232E308 为正值。

"#" is the "type-declaration character" for a Double. Following a number with this symbol means that it will treat the number as a double instead of trying to guess what exact variable type to use (it would likely have treated the 0 as a integer without this)

“#”是 Double 的“类型声明字符”。跟随带有此符号的数字意味着它将将该数字视为双精度数,而不是尝试猜测要使用的确切变量类型(如果没有此符号,它可能会将 0 视为整数)

回答by Andrey

Visual Basic uses the pound sign (# ) to indicate double-precision values. So 0#enforces to treat this constant as of type double. CDblconverts expression to double type. * Double means double precision floating point.

Visual Basic 使用井号 (#) 来指示双精度值。因此0#强制将此常量视为 double 类型。CDbl将表达式转换为双精度类型。* Double 表示双精度浮点数。

回答by Paul Michaels

CDbl casts the contents to a double value. The # indicates it's a numeric double value. VB and VBA are sometimes quite forgiving when you're dealing with numbers, which can prove to be dangerous!

CDbl 将内容转换为双精度值。# 表示它是一个数字双精度值。当您处理数字时,VB 和 VBA 有时会非常宽容,这可能会被证明是危险的!