Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2006

Tip: Looking for answers? Try searching our database.

The use of the "#" sign in VBA code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ExcelMonkey - 20 Mar 2006 15:49 GMT
I just came across some code which uses the "#" sign.  I seems to be using it
when delcaring constants:

Const Variable1 As Integer = 10#

What is the # sign doing?  Why would you use it?

Thanks

EM
Tom Ogilvy - 20 Mar 2006 15:50 GMT
It is used to explicitly cast the type of a variable or constant (in the case
of numbers)

From the immediate window.
? typename(10#)
Double
? typename(10%)
Integer
? typename(10!)
Single
? typename(10&)
Long

In the instance you show, since the constant is declared as integer, it
seems a bit redundant.  It would more commonly be used to avoid a VBA's
implicit conversion when it causes problems.  

for example
? 32000 * 10
causes an overflow error (error 6) since both variables are treated as
integers

? 32000! * 10
320000
works OK becuase 3200 is then treated as a long

You might be more familiar with variable declarations that use a $ sign for
string

Dim i$, j$

rather than
Dim i as string, j as String

? typename(i$)
String

Signature

Regards,
Tom Ogilvy

> I just came across some code which uses the "#" sign.  I seems to be using it
> when delcaring constants:
[quoted text clipped - 6 lines]
>
> EM
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.