View Full Version : What is the difference between string$(.. and string(.. ?


RECrerar
08-08-2008, 06:05 AM
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

redneckgeek
08-08-2008, 06:37 AM
From the Access (XP) help file:


Some functions have two versions: one that returns a Variant data type (http://javascript<b></b>:hhobj_3.Click()) and one that returns a String data type (http://javascript<b></b>:hhobj_4.Click()). The Variant versions are more convenient because variants handle conversions between different types of data automatically. They also allow Null (http://javascript<b></b>:hhobj_5.Click()) to be propagated through an expression (http://javascript<b></b>:hhobj_6.Click()). 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 (http://javascript<b></b>:hhobj_7.Click()).

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.

MSAccessRookie
08-08-2008, 07:53 AM
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."

georgedwilkinson
08-08-2008, 07:59 AM
The "$" is a hold over from old Basic (before QBasic). It indicates a string, as previously alluded to.

redneckgeek
08-08-2008, 08:27 AM
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"

Brianwarnock
08-08-2008, 08:34 AM
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

Banana
08-08-2008, 08:38 AM
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.

Brianwarnock
08-08-2008, 08:41 AM
I get confused enough don't make it worse. :(

Brian

Banana
08-08-2008, 08:48 AM
I get confused enough don't make it worse. :(

Brian

Sorry about that.

I thought you were retired? ;)

Brianwarnock
08-08-2008, 10:54 AM
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