Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default The use of the "#" sign in VBA code

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default The use of the "#" sign in VBA code

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


--
Regards,
Tom Ogilvy


"ExcelMonkey" wrote:

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
How to "sign" macro with "digital certificate"? Clueless in Seattle New Users to Excel 5 March 23rd 08 02:48 AM
How do display a "+" or "-" sign when hiding columns? DTI Tustin Setting up and Configuration of Excel 1 July 13th 06 01:21 PM
Can you "duplicate" "copy" listboxes and code to multiple cells? HotRod Excel Programming 1 September 1st 04 05:03 PM
Looking for VB code to test for "RING" , "BUSY" disconnects or other signals BruceJ[_2_] Excel Programming 3 November 20th 03 01:55 AM


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

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"