Wrox Programmer Forums
|
BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003
This is the forum to discuss the Wrox book Professional VB.NET 2003 by Bill Evjen, Billy Hollis, Rockford Lhotka, Tim McCarthy, Jonathan Pinnock, Rama Ramachandran, Bill Sheldon; ISBN: 9780764559921
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 13th, 2005, 07:03 PM
Registered User
 
Join Date: Feb 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 5 - Properties

Hello,

I am having problems understanding the SelectedCustomer property in the ArrayList example. So far I understand how properties work when applied to classes or structures. For instance the name property which concatenates the first and last name elements of the customer structure. I see this particular property is defined within the structure. Pretty straightforward stuff.

However the SelectedCustomer property is defined from Form1 as a Customer. Following through the tutorials I understand what the code does within the property but I don't understand what the property is? Why have you defined a property that is a customer? Why is the code defined as a property at all and not simply a function?

I think this section warrants an explanation of property types, or at least a better explanation of what the SelectedCustomer property is, as the only mention in the book is an explanation of what the property returns to the caller which is to return the listbox listIndex. The code is simple enough but understanding how the property fits in with the application and how it is used with the IsEmpty method is crucial to learning how these objects all fit together.

Sadly I am at a point where I understand how the application as a whole works but I am stuck on properties.

I hope I have explained myself clearly and perhaps you could assist in the definition of thse properties?

Many thanks.

 
Old February 16th, 2005, 06:05 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Could you please tell me what page and chapter you are referring to so that I may be able to further help you understand this?

Thearon
 
Old February 20th, 2005, 11:42 AM
Registered User
 
Join Date: Feb 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I was stuck on chapter 5, page 160 of Beginning VB.NET 2003. Since then I think I understand a bit better what's happening. The SelectedCustomer property actually returns the customer structure (rather than the listbox index) of the selected customer in the list. So the IsEmpty method checks the FirstName member of that selected customer.

What I missed is that two lists are being maintained: the _customers ArrayList and the ListBox items, the latter of which is the most confusing as when I last used VB5 or 6, the listbox simply held a list of string items, but now you can add structures.

I am not sure how the remove method works though as you don't appear to specify the index of the list item to remove, so if you have multiple items that are the same then will it always delete the first item?

Many thanks,

Neil

 
Old February 21st, 2005, 08:25 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Neil,

The _customers variable is defined as an ArrayList which stores objects. When you call the Delete method on a variable defined as an ArrayList, the ArrayList class performs a search through each object defined and uses the Object.Equals method to determine if the object at the current position in the ArrayList matches the object to be deleted. If not it moves on to the next object and again performs the comparison between objects until it finds a match and then deletes it.

I hope this helps.

Thearon
 
Old February 24th, 2005, 10:35 PM
Registered User
 
Join Date: Feb 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

Page 160 states the following: "Due to the way structures work, the caller will be given a Customer structure regardless of whether or not one was actually selected."

I find this odd. What is the reasoning behind this methodology? I would assume that you would want to return a structure only if one was selected. In the case that a structure has not been selected, which Customer structure is returned? Is it a random one from the list or an empty structure? I would assume it would be an empty structure as you test this in the IsEmpty function within the Customer structure.

 
Old February 26th, 2005, 06:36 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

The property that you are refering to returns a Customer structure when the property is called, hence it is the way that the property works and not the way structures work. As you eluded to the next section of code on that page does perform a test to see if you are dealing with an empty structure. If no index was specified when calling the SelectedCustomer property an empty structure is returned.

Thearon
 
Old February 26th, 2005, 09:55 PM
Registered User
 
Join Date: Feb 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So if I understand you correctly, since the Property - SelectedCustomer() is defined to return a Customer structure, it always returns one regardless of whether an actual customer was selected from the list. So I suppose the aforementioned sentence in the book should read:

"Due to the way properties work, the caller will be given a Customer structure whether or not one was actually selected."

Is this a reasonable assumption?

Tim

 
Old February 26th, 2005, 10:14 PM
Registered User
 
Join Date: Feb 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Accessing Collections

I need more clarity with regards to methods of accessing collections. In the 'Structure Demo' example initially the property SelectedCustomer() had the following line of code:

Return lstCustomers.Items(lstCustomers.SelectedIndex)

This is changed later on when we define our on collection to:

Return _customers(lstCustomers.SelectedIndex)

In the first example, it appears that we are accessing the collection through the listbox control, whereas in the second example it looks like we are accessing the collection directly. Is this correct reasoning?

Hope I am not asking too many questions. I am new to programming and have a lot to learn!

tim

 
Old February 28th, 2005, 06:03 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Tim,

Can you give me the page number of the code question so that I may look this up and try to answer your questions?

Thearon





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 8 - Implementing ViewState Properties janla2112 ASP.NET 3.5 Basics 4 October 21st, 2008 03:57 PM
properties aadz5 C# 3 December 29th, 2003 11:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.