在VBA宏中使用符号#(哈希) [英] Use of symbol # (hash) in VBA Macro

查看:156
本文介绍了在VBA宏中使用符号#(哈希)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Excel VBA中使用符号的含义是什么?

What is the meaning of the use of the # symbol in Excel VBA?

它被用于这个:

 a = b /100#

100 之后,我不明白的意义?

I don't understand the significance of # after the 100?

推荐答案

Double的类型声明字符是数字符号(#)。也称为 HASH

The type-declaration character for Double is the number sign (#). Also called HASH

其他类型的声明字符是:

Other type declaration characters are:


  1. 整数%

  2. 长&

  3. 货币@

  4. 单! b $ b
  5. Double#

  6. String $

  1. Integer %
  2. Long &
  3. Currency @
  4. Single !
  5. Double #
  6. String $




不明白#在这里的意义。

Don't understand the significance of # here.

这意味着当表达式被评估时,前面的
类型声明字符被视为特定的数据类型,而不是
a Variant。

It implies that when the expression is evaluated, the number in front of the type declaration character is treated as a specific data type instead of as a Variant.

看到这个例子,基本相同。 >

See this example, which are basically the same.

Sub Sample1()
    Dim a#

    a = 1.2

    Debug.Print a
End Sub

Sub Sample2()
    Dim a As Double

    a = 1.2

    Debug.Print a
End Sub

编辑

请详细解释一下。

考虑这个两个程序

Sub Sample1()
    Dim a As Double, b As Integer

    b = 32767
    a = b * 100

    Debug.Print a
End Sub

Sub Sample2()
    Dim a As Double, b As Integer

    b = 32767
    a = b * 100#

    Debug.Print a
End Sub

问题:其中一个将失败。你可以猜出哪一个?

Question: One of them will fail. Can you guess which one?

Ans :第一个程序 Sub Sample1()将会失败。

Ans: The 1st procedure Sub Sample1() will fail.

原因

Sample2 ,当您执行 b * 100#计算结果将为 Double 。由于它是Double的限制,所以计算成功,结果被分配给变量 a

In Sample2, when you do b * 100# the result of calculation will be of type Double. Since it is within the limits of Double, so the calculation succeeds and the result is assigned to variable a.

现在在 Sample1 中,当您执行 b * 100 计算结果将为整数,因为这两个操作数都是整数类型。但计算结果超过了整数存储的限制。结果将会出错。

Now in Sample1, when you do b * 100 the result of calculation will be of type Integer, since both the operands are of type integer. But the result of calculation exceeds the limits of Integer storage. As a result it will error out.

希望它有帮助:)

这篇关于在VBA宏中使用符号#(哈希)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆