#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default 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!


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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default 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!





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #5   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default 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!






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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!



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 05:14 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"