问题描述
我正在尝试调试损坏的查询.查询使用Left $([blahblah],4)而不是Left([blahblah],4).
I am trying to debug a broken query. The query usesLeft$([blahblah],4) instead of Left([blahblah],4).
在其中的Left()和Left $()函数之间有什么区别Microsoft Access?
What is the difference between the Left() and Left$() functions inMicrosoft Access?
推荐答案
结尾的$是String数据类型的类型声明字符VBA.
The trailing $ is a type declaration character for the String data type inVBA.
从Left $()返回的结果是一个字符串,而Left()返回一个变体.
The result returned from Left$() is a string, whereas Left() returns aVariant.
如果有可能出现Null值,则必须使用Left(),而不是Left $(),因为Variant可以为Null,但String不能为Null.为了证明这一点:
You must use Left(), not Left$() if there is any chance of Null values,since the Variant can be Null but the String cannot. To demonstrate that:
-
按Ctrl + G打开Immedate窗口.
Press Ctrl+G to open the Immedate window.
输入:?左(空,1)答案是空.
Enter:? Left(Null,1)The answer is Null.
现在输入:?左$(Null,1)这将生成错误94.由于结果应为Null,因此字符串为不能为Null,则会收到错误消息:无效使用Null".
Now enter:? Left$(Null,1)This generates Error 94. Since the result should be Null, and the Stringcannot be Null, you receive the error, "Invalid use of Null".
如果要处理字符串值,则在VBA代码中,Left $()会稍微变小效率更高,因为它避免了与变体.但是,如果可能有任何个可能涉及空值的情况,请使用Left(),否则用诸如Nz()之类的东西显式处理Null.
If you are dealing with string values, in VBA code, Left$() will be slightlymore efficient, as it avoids the overhead/inefficieny associated with theVariant. However, if there is any chance that Nulls may be involved, useLeft(), or else explicitly handle the Null with something such as Nz().
left()如果返回NULL,将返回一个字符串或NULL
left() will return a string or NULL if passed NULL
有关Null的更多信息: http://allenbrowne.com/casu-11.html
More information on Nulls:http://allenbrowne.com/casu-11.html
这篇关于Access中Left()和Left $()函数之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!