What is the difference between string$(.. and string(.. ?

RECrerar

Registered User.
Local time
Today, 06:37
Joined
Aug 7, 2008
Messages
130
Just a quicky, what does the dollar sign do?

I've got a bit of code I found here which sets up a buffer using
username = string$(255,0)
yet can also run the code without the $. I'm assuming the $ changes the way the variable acts but can't find anythign to tell me in what way in the help. Any cahnge of a quick explanation?

Thanks
 
From the Access (XP) help file:

Some functions have two versions: one that returns a Variant data type and one that returns a String data type. The Variant versions are more convenient because variants handle conversions between different types of data automatically. They also allow Null to be propagated through an expression. The String versions are more efficient because they use less memory.



Consider using the String version when:
  • Your program is very large and uses many variables.
  • You write data directly to random-access files.
The following functions return values in a String variable when you append a dollar sign ($) to the function name. These functions have the same usage and syntax as their Variant equivalents without the dollar sign.
 
From the Access (XP) help file:


Where in the Help file is this? I looked becasue I wanted to see the list that your quote referred to.

"The following functions return values in a String variable when you append a dollar sign ($) to the function name. These functions have the same usage and syntax as their Variant equivalents without the dollar sign."
 
The "$" is a hold over from old Basic (before QBasic). It indicates a string, as previously alluded to.
 
Where in the Help file is this? I looked becasue I wanted to see the list that your quote referred to.
"The following functions return values in a String variable when you append a dollar sign ($) to the function name. These functions have the same usage and syntax as their Variant equivalents without the dollar sign."

I could only find it indirectly. I went to the help for LTrim, and the used the See Also to get to "Returning Strings From Functions"
 
This is the problem with Microsoft's help, its often harder to use than the product.
Why are all of the functions you can use in queries not available in the standard help, how many newbies realise you have to open the VBA editor to find them?

Brian
 
This is the problem with Microsoft's help, its often harder to use than the product.
Why are all of the functions you can use in queries not available in the standard help, how many newbies realise you have to open the VBA editor to find them?

Brian

And I doubt that the expressions you use in QBE are same as one you use in VBA.

Imagine my surprise when Brent & ChrisO told me that Iif() in QBE isn't same as Iif() in VBA!



OP-

I suspect that for most parts, Microsoft uses Variant as the default data type so novice programmers wouldn't get all tripped over an conversion error; in other words, they were trying to help us out by giving us sugary functions that will play nice with bad data type.

If you're already quite strict with what data types you use, then you would benefit to use string-only version because that saves computer from extra overhead of processing the variant to verify that it's indeed a string before doing anything useful with it. The difference is probably few ms at best, but cumulatively, it can add up, especially if you re doing lot of data processing with strings.

With numeric types, it is slightly more useful in allowing you to mix'n'match different number types without getting an error. Not most efficient but lot of people do use an Integer to hold a variable for what should be Long, and vice versa.
 
I thought you were retired? ;)

I am but I like to excersie the old brain cells and I can still help newbies, tho' as more move to vista/2007 that will cease as I have no plans to upgrade.

Brian
 

Users who are viewing this thread

Back
Top Bottom