ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Dim (https://www.excelbanter.com/excel-programming/363614-dim.html)

Steph

Dim
 
Hi. I'm getting familiar with code that someone else wrote, and ran across
something I have never seen before. What is the difference between:
Dim Msg
Dim Msg$
What does the $ do? Thanks!



Tom Ogilvy

Dim
 
that is a form of implicit typing

? typename(msg)
Empty '<== means it is an uninitialized variant
? typename(msg1$)
String

so
Dim msg ' declares it as variant
Dim msg$ ' declares it as String
Dim msg& ' declares it as Long
Dim msg! 'declares it as Single
Dim msg# 'declares it as double
Dim msg% 'declares it as Integer

--
Regards,
Tom Ogilvy


"Steph" wrote:

Hi. I'm getting familiar with code that someone else wrote, and ran across
something I have never seen before. What is the difference between:
Dim Msg
Dim Msg$
What does the $ do? Thanks!




Steph

Dim
 
So essentially it saves you a few keystrokes: Dim Msg$ is the same as Dim
Msg as String.
Got it. Thanks Tom.

"Tom Ogilvy" wrote in message
...
that is a form of implicit typing

? typename(msg)
Empty '<== means it is an uninitialized variant
? typename(msg1$)
String

so
Dim msg ' declares it as variant
Dim msg$ ' declares it as String
Dim msg& ' declares it as Long
Dim msg! 'declares it as Single
Dim msg# 'declares it as double
Dim msg% 'declares it as Integer

--
Regards,
Tom Ogilvy


"Steph" wrote:

Hi. I'm getting familiar with code that someone else wrote, and ran
across
something I have never seen before. What is the difference between:
Dim Msg
Dim Msg$
What does the $ do? Thanks!






Dave Peterson

Dim
 
Dim Msg
declares Msg as a variant.

It can hold anything--numbers, text, objects...

Dim Msg$
is the same as
dim Msg as String

That $ sign is one of the several type declaration character shortcuts. (I find
them difficult to remember, so I don't use them.)

# = Double
% = Integer
& = Long
@ = Currency
! = single
$ = string



Steph wrote:

Hi. I'm getting familiar with code that someone else wrote, and ran across
something I have never seen before. What is the difference between:
Dim Msg
Dim Msg$
What does the $ do? Thanks!


--

Dave Peterson

Ed

Dim
 
Hi, Steph. It's called a "type-declaration character". The $ defines the
variable as a string. Here's some more info:

http://support.microsoft.com/kb/191713/en-us
http://msdn2.microsoft.com/en-us/library/s9cz43ek.aspx

"Steph" wrote in message
...
Hi. I'm getting familiar with code that someone else wrote, and ran
across something I have never seen before. What is the difference
between:
Dim Msg
Dim Msg$
What does the $ do? Thanks!





Jim Thomlinson

Dim
 
To further Tom's answer check out this link.

http://www.dailydoseofexcel.com/arch...on-efficiency/

It deals with a number of string functions such as Trim, Left, ... and
explains the benefits of using Trim$ and Left$...
--
HTH...

Jim Thomlinson


"Tom Ogilvy" wrote:

that is a form of implicit typing

? typename(msg)
Empty '<== means it is an uninitialized variant
? typename(msg1$)
String

so
Dim msg ' declares it as variant
Dim msg$ ' declares it as String
Dim msg& ' declares it as Long
Dim msg! 'declares it as Single
Dim msg# 'declares it as double
Dim msg% 'declares it as Integer

--
Regards,
Tom Ogilvy


"Steph" wrote:

Hi. I'm getting familiar with code that someone else wrote, and ran across
something I have never seen before. What is the difference between:
Dim Msg
Dim Msg$
What does the $ do? Thanks!





All times are GMT +1. The time now is 04:06 AM.

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