PC Review


Reply
 
 
kylefoley2000
Guest
Posts: n/a
 
      3rd Apr 2010
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
 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      4th Apr 2010
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
<(E-Mail Removed)> 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

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      4th Apr 2010
Looking this up in VBA help we get

Returns a String containing the character associated with the specified
character code.

--

HTH

Bob

"kylefoley2000" <(E-Mail Removed)> wrote in message
news:8C228318-C238-4DCA-B282-(E-Mail Removed)...
> 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



 
Reply With Quote
 
Joe User
Guest
Posts: n/a
 
      4th Apr 2010
"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

 
Reply With Quote
 
kylefoley2000
Guest
Posts: n/a
 
      4th Apr 2010
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

 
Reply With Quote
 
Joe User
Guest
Posts: n/a
 
      4th Apr 2010
"Chip Pearson" <(E-Mail Removed)> 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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
> <(E-Mail Removed)> 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


 
Reply With Quote
 
Joe User
Guest
Posts: n/a
 
      4th Apr 2010
"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

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      4th Apr 2010
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" <(E-Mail Removed)> wrote in message
news:A957A2B7-D2DD-4F25-8CD6-(E-Mail Removed)...
> 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


 
Reply With Quote
 
JLatham
Guest
Posts: n/a
 
      4th Apr 2010
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

 
Reply With Quote
 
JLatham
Guest
Posts: n/a
 
      4th Apr 2010
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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:51 PM.