vba &符号和 $ 符号在以下上下文中是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16188066/
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 20:48:20  来源:igfitidea点击:

What does the ampersand and $ symbol mean in the following contexts?

vbams-access-2007access-vba

提问by Katana24

I'm in the process of a code review and have come across this:

我正在进行代码并遇到了这个问题:

Dim lngLen As Long    
lngLen = 16&

I have done some reading and it appears to be that this is a way of casting the number to a long - is that correct?

我已经阅读了一些资料,这似乎是一种将数字转换为 long 的方法 - 对吗?

But is that really necessary here as you can just assign lngLenthe value of 16 because it's a numeric value.

但是这里真的有必要吗,因为您可以只分配lngLen16 的值,因为它是一个数值。

Also, following this code this is done:

此外,按照此代码完成:

Dim strCompName As String   
strCompName = String$(lngLen, 0&)

I realize the Stringmethod, from the Access help definitions, "returns a variant containing a repreating character string of the length specified."

String从 Access 帮助定义中实现了该方法,“返回一个包含指定长度的重复字符串的变体。”

So what does the $ do? And again is the & casting the 0 to a long?

那么美元有什么作用呢?又是 & 将 0 转换为 long 吗?

采纳答案by KevinIsNowOnline

Hi you can check this questionfor a possible answer to your query.

您好,您可以查看此问题以获得您查询的可能答案。

Edit: Moreover, I was able to scour the internet for more resources and I found this VBA typing conventionwhich originally found on this forum page.

编辑:此外,我能够在互联网上搜索更多资源,我发现了最初在此论坛页面上找到的 VBA类型约定

Hopefully this would help you.

希望这会帮助你。

回答by Brad Hangs

Well as per you inquiry

根据您的询问

Some people think Choosing the function that returns the correct type will be slightly more efficient and this makes faster executing code.

有些人认为选择返回正确类型的函数会稍微高效一些,这样可以更快地执行代码。

Well on the other hand some thinks It serves no useful purpose at all to add the type declaration suffix in the code when it was not declared with the suffix. Surely that does nothing but obfuscate the code.

好吧另一方面,有些人认为在代码中添加类型声明后缀没有任何用处,因为它没有用后缀声明。当然,这只会混淆代码。

String$ is a function
The $ at the end is a way of declaring the variable As String.
The & at the end is a way of declaring the variable As Long.

You are right i dont think these are necessary here.

你是对的,我不认为这些在这里是必要的。