View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Question about dim statement

Hi Gregg,

Dim lNumber, lValue, lWhatever as Long


the above line does *not* dim each of the three variables as long; INumber
is implicitly dimmed as variant and Ivalue is similarly dimmed as variant.
IWhatever is, howver, explicitly dimmed as long.

This has nothing to do with single or multiline declaration which is
essentially a question of style. So, to explicitly dim the three variables
in a single line declaration, you would write it thus::

Dim lNumber as Long, lValue As Long , lWhatever as Long

Normally, using the implicit default variant may be less efficient but
whether it can engender subtle problems depends on the code you are using.
Personally, I have rarely encountered such a problem. But then again, I
endeavour always to explicitly declare variables.



---
Regards,
Norman



"Gregg" wrote in message
oups.com...
While debugging my code today, I was surprised to find the fix was to
change this dim statement...
Dim lNumber, lValue, lWhatever as Long

to this...
Dim lNumber as Long
Dim lValue as Long
Dim lWhatever as Long

The value would not work correctly unless I separated out the dim
statement. Once I did that, it worked flawlessly and I set it back and
forth to be sure.

I've never encountered that before. I've always been able to place
multiple items in a dim statement. Is Long different? Can someone
enlighten me on this?

Thanks.