简体   繁体   English

在某些函数名称中尾随“ $”的含义是什么?

[英]What is significance of trailing “$” in some function names?

I recently looked at some vba source at Microsoft: [Convert Fractions to Decimal Values][1] 我最近查看了Microsoft的一些vba资料:[将小数转换为十进制值] [1]

[1]: https://support.microsoft.com/en-us/kb/185424 and I noticed that several functions had a trailing "$", specifically trim$(), left$(), and mid$(). [1]: https//support.microsoft.com/zh-cn/kb/185424 ,我注意到几个函数的尾部带有“ $”,特别是trim $(),left $()和mid $() 。 My question is: what does the "$" signify? 我的问题是:“ $”代表什么?

I downloaded the microsoft function and it ran correctly under Excel 2007. 我下载了Microsoft函数,它在Excel 2007下可以正确运行。

Since VBA trim() works differently from the worksheet function trim(), I wrote a small program to compare the operation of the 3 possible trim() calls. 由于VBA trim()与工作表函数trim()的工作方式不同,因此我编写了一个小程序来比较3个可能的trim()调用的操作。 I found that trim() and trim$() produced identical output. 我发现trim()和trim $()产生相同的输出。 worksheetfunction.trim(), of course, produces output that has extraneous space characters removed from inside the string. 当然,worksheetfunction.trim()产生的输出具有从字符串内部删除的多余空格字符。

I am very curious about the trailing "$", and will be grateful for enlightenment! 我对尾随的“ $”感到很好奇,并希望能给您带来启发!

Thank you, Dave 谢谢戴夫

To quote from https://bytes.com/topic/access/answers/196893-difference-between-left-left-function 引用https://bytes.com/topic/access/answers/196893-difference-between-left-left-function

Allen Browne 艾伦·布朗
The trailing $ is a type declaration character for the String data type in VBA. 尾随的$是VBA中String数据类型的类型声明字符。 The result returned from Left$() is a string, whereas Left() returns a Variant. 从Left $()返回的结果是一个字符串,而Left()返回一个Variant。 You must use Left(), not Left$() if there is any chance of Null values, since the Variant can be Null but the String cannot. 如果可能会有Null值,则必须使用Left(),而不是Left $(),因为Variant可以为Null,而String不能。

That post has a full worked example 那篇文章有一个完整的例子

The syntax is a left-over habit from ancient history. 语法是古代历史遗留下来的习惯。 In early versions of Basic variables did not have to be declared but data types were implied by the name of the variable. 在早期版本的Basic变量中,不必声明,但是变量名隐含了数据类型。 Any variable ending with $ was a string and any variable ending with % was an integer. 以$结尾的任何变量都是字符串,以%结尾的任何变量都是整数。

FORTRAN had a similar convention: any variable starting with the letters I, J, K, L, M or N were integers, all others were real. FORTRAN有一个类似的约定:以字母I,J,K,L,M或N开头的任何变量都是整数,其他所有变量都是实数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM