Using the $ after functions

  • Thread starter Thread starter TheUbe
  • Start date Start date
T

TheUbe

This is a general question...Is there any difference using a function in the
expression builder that ends with the $ and one that does not?
 
So For Example:

Dim AnyString, MyStr
AnyString = "Hello World" ' Define string.

mystring = Left$(AnyString)

I would not need to use the variant that defined how many characters from
the left I wanted it would return the entire string?
 
TheUbe said:
This is a general question...Is there any difference using a function in the
expression builder that ends with the $ and one that does not?

The ones with $ may be a tiny bit faster, but they can not
deal with a Null argument. In many situations, the ability
to deal with Null is far more efficient than using other
mechanisms.
 
No that would error, you must specify a length. Of course, you could specify
a length of 5000 and just get the entire string.

Left$(Null,5000) will generate an error
Left(Null,5000) will return null



John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
TheUbe said:
So For Example:

Dim AnyString, MyStr
AnyString = "Hello World" ' Define string.

mystring = Left$(AnyString)

I would not need to use the variant that defined how many characters from
the left I wanted it would return the entire string?

No, by "variant" we mean a data type of "variant".

Variant data types can take on "any" type of value. integer, strings, date,
or null....

the "null" is particularly important here, since if you are dealing with
recordsets (and sql), then values return MIGHT be null.

try this in the debug windows:

? left(null,5)

? left$(null,5)

The 2nd example with the $ will ERROR out. In other words, you can NOT use
null
values if you use the $, but you *can* if you leave out the $.

So left() can accept a null value, but left$() cannot....
 
Back
Top