#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default chr$

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default chr$

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
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 834
Default chr$

Looking this up in VBA help we get

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

--

HTH

Bob

"kylefoley2000" wrote in message
...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 905
Default chr$

"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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default chr$

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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 905
Default chr$

"Chip Pearson" 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" wrote in message
...
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
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


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 905
Default chr$

"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

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default chr$

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" wrote in message
...
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


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default chr$

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

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default chr$

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



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default chr$

This has apparently been a very boring Saturday. <vbg


"kylefoley2000" wrote in message
...
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



  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default chr$

Naaaahhhh...
Boring would have been telling him that the second loop is going to output
hey:
A
followed by
hey:
B
followed by
hey:
C
ad nauseum, or until sleep overcomes one of us!
<g

"JLGWhiz" wrote:

This has apparently been a very boring Saturday. <vbg


"kylefoley2000" wrote in message
...
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



.

  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 905
Default chr$

"JLatham" wrote:
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().


"In the beginning", BASIC had no type declarations. Instead, the type was
implied by naming conventions. Original BASIC had only string and numeric
variables. Some versions of BASIC evolved additional naming conventions,
such as suffixes to distinguish integer and floating-point variables. All
of this predates Microsoft and MS BASIC by about two decades, and it
predates the ANSI BASIC standard by more than a decade.

So what? That is really a very different language than MS Visual BASIC and
VBA.


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

"JLatham" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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



All times are GMT +1. The time now is 04:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"