View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Question about dim statement

When you do this:
Dim lNumber, lValue, lWhatever as Long
it's seen as:
Dim lNumber as Variant, lValue as Variant, lWhatever as Long

But I'm not sure what you had to fix to make it work. But I would suspect it
had something to do with the way a Long is initialized (as 0) vs a Variant (as
Empty).

But
if lnumber = 0 then
msgbox "hi"
end if

worked ok for me in xl2003. (It saw that I wanted to compare numbers and Empty
was treated as zero.)

Dim lNumber as long, lValue as long, lWhatever as long

if you wanted just one line



Gregg wrote:

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.


--

Dave Peterson