From: Joe User on
"Chip Pearson" <chip(a)cpearson.com> wrote:
> When a $ character is at the end of a string function
> such as Chr, it tells VBA to use the String, as
> opposed to the Variant, version of the function.

I did not know there were two versions and they can co-exist. The Chr
Function Help page describes only a function that returns type String. Live
and learn!

I presume the ability to have two versions of functions(different types) is
limited to intrinsic VBA functions. I get an error when I try to create a
Variant and String function with the same name in the same module. When I
create Public Variant and String functions with the same name in different
module, Call funcName$ calls whichever function is in the same module, even
it is Variant function(!); but x = funcName$ raises a compiler error when
called in the module with the Variant function declaration. Call funcName$
also raises a compiler error when called from a module with no function
declaration of the name.


----- original message -----

"Chip Pearson" <chip(a)cpearson.com> wrote in message
news:csifr5t0vss4onflhp4q1rj04pdklt7t24(a)4ax.com...
> When a $ character is at the end of a string function such as Chr, it
> tells VBA to use the String, as opposed to the Variant, version of
> the function. In most respects, it is irrrelevant whether you use the
> $ version of the function.
>
> Cordially,
> Chip Pearson
> Microsoft Most Valuable Professional,
> Excel, 1998 - 2010
> Pearson Software Consulting, LLC
> www.cpearson.com
>
>
>
>
>
> On Sat, 3 Apr 2010 15:41:01 -0700, kylefoley2000
> <kylefoley2000(a)discussions.microsoft.com> wrote:
>
>>what does chr$ mean in this code
>>
>>Sub rick()
>>Dim strabc(1 To 26) As String
>>Dim i As Integer
>>Dim strprompt As String
>>For i = 1 To 26
>> strabc(i) = Chr$(i + 64)
>>Next i
>>strprompt = "hey:" & vbCrLf
>>For i = 1 To 26
>> strprompt = strprompt & strabc(i)
>>Next i
>>MsgBox strprompt
>>
>>
>>End Sub

From: Joe User on
"kylefoley2000" wrote:
> great answer

Maybe not. Stay tuned for Chip's response. It was posted to another
server. It takes 30-40 min to propagate to the MSDG web server, in my
experience.

(It should be showing up momentarily.)


----- original message -----

"kylefoley2000" wrote:
> great answer, thank you for your dedication and support
>
> "Joe User" wrote:
>
> > "kylefoley2000" wrote:
> > > what does chr$ mean in this code
> >
> > It's superfluous.
> >
> > Putting "$" after a variable name ensures that it is treated as String
> > variable, even if it is not declared as such (and it is not declared as
> > something else, and it Option Explicit is not declared).
> >
> > But putting "$" after a function name has not functional value since
> > functions, especially intrinsic VBA functions, are typed explicitly.
> >
> > However, some people might argue that putting "$" after any name is
> > self-documenting. That is, it makes it clearer to the reader what the code
> > is doing.
> >
> > There are many other date-type suffixes. "%" for Integer; "#" for Double;
> > and "@" for Currency, to name a view. These numeric suffixes are especially
> > useful following constants.
> >
> >
> > ----- original message -----
> >
> > "kylefoley2000" wrote:
> >
> > > what does chr$ mean in this code
> > >
> > > Sub rick()
> > > Dim strabc(1 To 26) As String
> > > Dim i As Integer
> > > Dim strprompt As String
> > > For i = 1 To 26
> > > strabc(i) = Chr$(i + 64)
> > > Next i
> > > strprompt = "hey:" & vbCrLf
> > > For i = 1 To 26
> > > strprompt = strprompt & strabc(i)
> > > Next i
> > > MsgBox strprompt
> > >
> > >
> > > End Sub
From: Rick Rothstein on
Joe gave you a great answer to a question you did not ask. Joe's answer
dealt with variable names and data type suffix characters, however you asked
about chr$ which is not a variable. Chr is a built-in VB String function and
most (but not all) String function have two forms... one that returns String
value directly (those have the $ sign suffix attached to them) and another
which returns a Variant value having a sub-type of String. In theory, using
the String value version (with the $ sign) is slightly faster than using the
Variant value version. The time difference is pretty much not noticeable
unless you have a huge loop performing extensive String manipulations
(making use of those functions) during each loop, and even then the time
differences should be somewhat smallish.

--
Rick (MVP - Excel)



"kylefoley2000" <kylefoley2000(a)discussions.microsoft.com> wrote in message
news:A957A2B7-D2DD-4F25-8CD6-1ECB30C7E421(a)microsoft.com...
> great answer, thank you for your dedication and support
>
> "Joe User" wrote:
>
>> "kylefoley2000" wrote:
>> > what does chr$ mean in this code
>>
>> It's superfluous.
>>
>> Putting "$" after a variable name ensures that it is treated as String
>> variable, even if it is not declared as such (and it is not declared as
>> something else, and it Option Explicit is not declared).
>>
>> But putting "$" after a function name has not functional value since
>> functions, especially intrinsic VBA functions, are typed explicitly.
>>
>> However, some people might argue that putting "$" after any name is
>> self-documenting. That is, it makes it clearer to the reader what the
>> code
>> is doing.
>>
>> There are many other date-type suffixes. "%" for Integer; "#" for
>> Double;
>> and "@" for Currency, to name a view. These numeric suffixes are
>> especially
>> useful following constants.
>>
>>
>> ----- original message -----
>>
>> "kylefoley2000" wrote:
>>
>> > what does chr$ mean in this code
>> >
>> > Sub rick()
>> > Dim strabc(1 To 26) As String
>> > Dim i As Integer
>> > Dim strprompt As String
>> > For i = 1 To 26
>> > strabc(i) = Chr$(i + 64)
>> > Next i
>> > strprompt = "hey:" & vbCrLf
>> > For i = 1 To 26
>> > strprompt = strprompt & strabc(i)
>> > Next i
>> > MsgBox strprompt
>> >
>> >
>> > End Sub

From: JLatham on
And to add yet more confusion to the whole thing:
In the Beginning there was BASIC and in BASIC there was CHR$(), but there
was no CHR(). Likewise there was DIR$() and it was without DIR(). And there
are similar examples of the original BASIC language that had the $ as a
required part of the function name that have operators now that have dropped
the $ and yet act in exactly the same manner, and are generally
interchangeable.

"kylefoley2000" wrote:

> what does chr$ mean in this code
>
> Sub rick()
> Dim strabc(1 To 26) As String
> Dim i As Integer
> Dim strprompt As String
> For i = 1 To 26
> strabc(i) = Chr$(i + 64)
> Next i
> strprompt = "hey:" & vbCrLf
> For i = 1 To 26
> strprompt = strprompt & strabc(i)
> Next i
> MsgBox strprompt
>
>
> End Sub
From: JLatham on
Oh - and I believe Bob Phillips actually answered the question: it returns a
character based on the numeric value derived by adding the 64 to the value of
i.
With i=1 to 26, you'll end up returning characters A through Z.

"kylefoley2000" wrote:

> what does chr$ mean in this code
>
> Sub rick()
> Dim strabc(1 To 26) As String
> Dim i As Integer
> Dim strprompt As String
> For i = 1 To 26
> strabc(i) = Chr$(i + 64)
> Next i
> strprompt = "hey:" & vbCrLf
> For i = 1 To 26
> strprompt = strprompt & strabc(i)
> Next i
> MsgBox strprompt
>
>
> End Sub