为什么我在VBA for Excel 2013中的'^'运算符之前需要一个空格,否则会产生一个编译时错误"Expected list or spacer". [英] Why do I need a space before the '^' operator in VBA for Excel 2013 or it will produce a compile time error "Expected list or separator"

查看:128
本文介绍了为什么我在VBA for Excel 2013中的'^'运算符之前需要一个空格,否则会产生一个编译时错误"Expected list or spacer".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我输入例如Sqr(a ^ 2 + b ^ 2),则没有错误.但是,当我键入Sqr(a ^ 2 + b^ 2)时,会产生我不理解的编译错误:

If I type for example Sqr(a ^ 2 + b ^ 2) there is no error. But when I type Sqr(a ^ 2 + b^ 2) it produces a compile error which I do not understand:

在VBA7中,^的功能与表示幂的_^(下划线表示空格)相反?

What is the function of ^ in VBA7 as opposed to _^ (underscore to show space) which denotes exponentiation?

推荐答案

这是64位 ^可能会使编译器在是否使用运算符与操作数值(如LongLong)之间产生混淆.

^ can confuse the compiler as to whether an operator versus operand value as LongLong is being used.

之所以会出现此问题,是因为在这种情况下,抑扬符(^)是不明确的.对于VBA的64位版本,抑扬符有两种含义:

This problem occurs because the circumflex character (^) is ambiguous in this context. For 64-bit versions of VBA, the circumflex has two meanings:

  1. 它可以将x表示为y的幂("x ^ y").
  2. 仅对于64位Office 2010 VBA版本,它可以指定将操作数值视为LongLong 64位整数值数据类型(例如,"234 ^").

请考虑以下情形:

Consider the following scenario:

您在计算机上安装了64位版本的Microsoft Office 2010 电脑.在Visual Basic IDE中,创建一个新项目.

You have the 64-bit edition of Microsoft Office 2010 installed on your computer. In the Visual Basic IDE, you create a new project.

在您的Visual Basic for Applications(VBA)代码中,键入一条语句 类似于以下内容:

In your Visual Basic for Applications (VBA) code, you type a statement that resembles the following:

LongLongVar2 = LongLongVar1 ^ IntegerVar

LongLongVar2 = LongLongVar1^IntegerVar

在64位Office 2010 VBA版本中键入x ^ y时,VBA IDE 编辑器不知道如何解释字符串的"x ^"部分.在 在这种情况下,"x ^"可以视为LongLong数据类型.如果 以这种方式解释"x ^",字符串将产生错误 因为没有为"y"值指定运算符 适用于"x"值.如果您使用空格输入字符串 在值名称和抑扬符(例如x ^ y)之间,您可以 表示您打算将该符号用作运算符而不是数据 类型指示符.通过这样做,您可以避免错误情况. 因此,示例表达式...应该重写如下:

When you type x^y in the 64-bit Office 2010 VBA editions, the VBA IDE editor does not know how to interpret the "x^" part of the string. In this context, "x^" can be treated as being the LongLong data type. If "x^" is interpreted in this manner, the string will produce an error because there is no operator that is specified for the "y" value to apply to the "x" value. If you type the string by using a space between the value name and the circumflex (for example, x ^y), you indicate that you intend the symbol to be an operator and not a data type designator. By doing this, you can avoid the error condition. Therefore, the example expression ... should be rewritten as follows:

LongLongVar2 = LongLongVar1 ^ IntegerVar

LongLongVar2 = LongLongVar1 ^ IntegerVar

这篇关于为什么我在VBA for Excel 2013中的'^'运算符之前需要一个空格,否则会产生一个编译时错误"Expected list or spacer".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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