What does the vb statement mean?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dim sCoName As String = oDs.Customers(0).CompanyName

The part that I want to understand is the oDs.Customers(0). Does
oDs.Customers(0) mean 1st row of the datatable Customers. Where can I find
more information about this?
 
Dim sCoName As String = oDs.Customers(0).CompanyName

The part that I want to understand is the oDs.Customers(0). Does
oDs.Customers(0) mean 1st row of the datatable Customers. Where can I find
more information about this?

Assuming that oDs.Customers is a DataTable, the index returns Rows().
It is the same as oDs.Customers.Rows(0).

I don't think indexing of objects is documented, at least I have never
seen any documentation except in examples.
 
Peter said:
Well, I have found that this is something called collection's index.
I find the information in here:
http://msdn2.microsoft.com/en-us/library/8bw9ksd6(VS.80).aspx.

Besides collection's index, it mentions that I can do the same thing
using collection-specific statements in your programming language.
How to do that in VB?

Peter


In general, it's a Default property. You can call a Default property by
omitting the property name. For example, if a class' Default property is
"Item", you can write

theObject.Item(Index)

or

theObject(Index)


A Default property is declared by using the Default keyword:

Default Public Property Item(ByVal Index As Integer) As Object

A class (a type) can only have one Default property. It is often used
whenever the nature of the class is something that contains items, similar
to an array whose items can also be accessed by the syntax
"TheArray(Index)".

It's purpose is just having less to type.


Armin
 
Hi Armin,

Thanks. Then how can I find out which property is the default property of a
class? I hope this kind of information is documented in MSDN Library for
each class.

Peter
 
Peter,

This is exactly as you and Armin say. However to add a little bit. What you
show is the part of a generated XSD file. Called a dataset. With Visual
Studio you can generate from an XSD file a class (in VBNet, C# or the other
2 supported languages).

If you instance from that class an object, than you can use it like you do.

To see that class you have in your Solution Explorer in top to set Show all
files.

Than you can open the class and have a look at it. For to make an XSD file
has Visual Studio a lot of tools.

Cor
 
Hi Cor,

How can I find out the default property of a class like DataTable, Dataset,
and etc.? I hope one does not need to review coding. I try to look at MSDN
Library for the default property for DataTable class and do not find
anything. I cannot even find the Item property for DataTable class.
 
Peter said:
Hi Armin,

Thanks. Then how can I find out which property is the default
property of a class? I hope this kind of information is documented
in MSDN Library for each class.


I think there is no "xy is the Default property" in the documentation for
each class, but if you read the declaration of the property, you see that it
is the Default property (eg "Public ReadOnly Default Property Item..."). You
also see the declaration in the object browser in the lower pane. (BTW, in
VB6, the default property was marked with a different icon, so it was
obvious at once).

Why do you need to know this? I have never looked for the Default property.
Instead, whenever I was using a property and saw/learned that it is the
default property, I was making use of the short syntax.


Armin
 
I think there is no "xy is the Default property" in the documentation for
each class, but if you read the declaration of the property, you see that it
is the Default property (eg "Public ReadOnly Default Property Item..."). You
also see the declaration in the object browser in the lower pane. (BTW, in
VB6, the default property was marked with a different icon, so it was
obvious at once).

Why do you need to know this? I have never looked for the Default property.
Instead, whenever I was using a property and saw/learned that it is the
default property, I was making use of the short syntax.

The main reason I care is when I am looking at sample code. Sometimes
it is not immediately obvious what the default property really is.
 
Jack Jackson said:
There is no Item property for DataTable. Rows() is the default
property.

A DataTable does not have a Default property, but the Rows property,
pointing to a DataRowCollection, does have the Item property as Default
property ("dt.rows(index)").


Armin
 
Back
Top