ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   "!" at end of variable (https://www.excelbanter.com/excel-programming/307531-end-variable.html)

joak

"!" at end of variable
 
Hi-

I have the pleasure of fixing another's vba code and,
having very little experience with vba myself, I had a
question about variable names.

From what I've read, vba variables shouldn't have !, &,
%, etc. in the name. However, in this particular piece
of code, there are some Dim statements declaring some
variables with an "!" at the end. In the actual code,
however, the "!" is left out. What is this all about?
TIA!

joak

Bob Phillips[_6_]

"!" at end of variable
 
Joak,

Declaring a variable in this way is typing it at the same time.

Dim a! is the same as Dim a As Single
Dim a% is the same as Dim a As Integer.

The variable though is just called a, so that is all you need to refer to it
by in the code.

Personally, I think it is ugly syntax, much better to declare the type
clearly.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"joak" wrote in message
...
Hi-

I have the pleasure of fixing another's vba code and,
having very little experience with vba myself, I had a
question about variable names.

From what I've read, vba variables shouldn't have !, &,
%, etc. in the name. However, in this particular piece
of code, there are some Dim statements declaring some
variables with an "!" at the end. In the actual code,
however, the "!" is left out. What is this all about?
TIA!

joak




JE McGimpsey

"!" at end of variable
 
It's not part of the variable name, per se. It's a type declaration
character. ! indicates a Single, so

Dim foo!

is equivalent to

Dim foo As Single

Each data type (other than Variant and Object) has a type declaration
character. You can see them in XL/VBA Help.


In article ,
"joak" wrote:


I have the pleasure of fixing another's vba code and,
having very little experience with vba myself, I had a
question about variable names.

From what I've read, vba variables shouldn't have !, &,
%, etc. in the name. However, in this particular piece
of code, there are some Dim statements declaring some
variables with an "!" at the end. In the actual code,
however, the "!" is left out. What is this all about?
TIA!


Chip Pearson

"!" at end of variable
 
Joak,

The '!' at the end of the variable name forces that variable to
be of type Single. The '!' is a substitute for "As Single".
Other type specification characters include

$ As String
# As Long
@ As Currency
% As Integer
& As Long


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"joak" wrote in message
...
Hi-

I have the pleasure of fixing another's vba code and,
having very little experience with vba myself, I had a
question about variable names.

From what I've read, vba variables shouldn't have !, &,
%, etc. in the name. However, in this particular piece
of code, there are some Dim statements declaring some
variables with an "!" at the end. In the actual code,
however, the "!" is left out. What is this all about?
TIA!

joak




joak

"!" at end of variable
 
Chip, JE, and Bob-
Ah, I get it now. Thank you very much! You guys are
great!

Joak

-----Original Message-----
Joak,

The '!' at the end of the variable name forces that

variable to
be of type Single. The '!' is a substitute for "As

Single".
Other type specification characters include

$ As String
# As Long
@ As Currency
% As Integer
& As Long


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"joak" wrote in

message
...
Hi-

I have the pleasure of fixing another's vba code and,
having very little experience with vba myself, I had a
question about variable names.

From what I've read, vba variables shouldn't have !, &,
%, etc. in the name. However, in this particular piece
of code, there are some Dim statements declaring some
variables with an "!" at the end. In the actual code,
however, the "!" is left out. What is this all about?
TIA!

joak



.


Chip Pearson

"!" at end of variable
 
# As Long

This should, of course, be As Double.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Chip Pearson" wrote in message
...
Joak,

The '!' at the end of the variable name forces that variable to
be of type Single. The '!' is a substitute for "As Single".
Other type specification characters include

$ As String
# As Long
@ As Currency
% As Integer
& As Long


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"joak" wrote in message
...
Hi-

I have the pleasure of fixing another's vba code and,
having very little experience with vba myself, I had a
question about variable names.

From what I've read, vba variables shouldn't have !, &,
%, etc. in the name. However, in this particular piece
of code, there are some Dim statements declaring some
variables with an "!" at the end. In the actual code,
however, the "!" is left out. What is this all about?
TIA!

joak






JE McGimpsey

"!" at end of variable
 
In article ,
"Bob Phillips" wrote:

Personally, I think it is ugly syntax, much better to declare the type
clearly.


That, and whoever decided that the *percent* sign should indicate an
*integer* should have been shot.


All times are GMT +1. The time now is 05:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com