View Single Post
  #16   Report Post  
Posted to microsoft.public.excel.programming
Tushar Mehta Tushar Mehta is offline
external usenet poster
 
Posts: 1,071
Default When do you need .Value?

Thanks for pointing that out, Alan. Apparently, .Net does support some
default properties ;-)

It would appear that at least when dealing with collections, 'Item'
indeed works as the default property. So, when one uses a range as a
collection, .Item is not needed.

But, Value definitely is not the default property for the range object.

Dim x as object
x=cells(1,1) will create an object reference to the cell, whereas
x=cells(1,1).value will create a simple data type (of the appropriate
numeric/string type) that contains a value.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
The reason I asked is that the On-line help attributes the availability
of the syntax

Range("a1:d4").Cells(1,2) [rather than Range("a1:d4").Cells.Item(1,2)],
thus by implication Range("a1:d4")(1,2) [rather than
Range("a1:d4.Item(1,2)],

to the fact that the Item Property is the default for the Range Object,
to wit:

"Because the Item property is the default property for the Range object,
you can specify the row and column index immediately after the Cells
keyword." [from the online help for the Cells Property]

Is the syntax Range("a1:d4")(1,2) not available in VB.Net to refer to
Cell B1?

Alan Beban

Tushar Mehta wrote:

Just that, Alan. The software will not make an inference about what
property it should refer to. So,

Dim x as Integer
x=Cells(1,1)

will not be interpreted as
x=Cells(1,1).Value

but an attempt to assign an object, i.e., Cells(1,1), to an integer
variable (x).

After all, .Net doesn't require a Set to assign an object to a
variable. So, if it supported a default property concept, the
following would be ambiguous:

Dim x as Variant
x=Cells(1,1)