p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 (http://p2p.wrox.com/book-beginning-visual-basic-2005-isbn-978-0-7645-7401-6-226/)
-   -   (Collection) appears in the list box (http://p2p.wrox.com/book-beginning-visual-basic-2005-isbn-978-0-7645-7401-6/57290-collection-appears-list-box.html)

Tracey April 30th, 2007 09:23 AM

(Collection) appears in the list box
 
I don't know if this is the correct forum for: 0-7645-7401-9 Wrox Beginning Visual Basic 2005.
If it is not can anyone direct me to the correct forum?
If so: Working with Structures page 150-152:
"(Collection)" appears 3 times in the list box instead of the Customer Entries.
I think I have typed the "Try It Out Using an ArrayList" as the book describes.
Can anyone show me were I am in error?
Thanks, Tracey
MSVS2005 Pro AE on Win2K.
ISBN: 0-7645-7401-9 Wrox Beginning Visual Basic 2005.
BTW:
I had to comment out objNewCustomers.Add(objCustomers): 'Add' is not a member of 'StructureDemo.Customer'
... and ...
Try It Out (Overriding ToString) on page 152 does NOT resolve/change anything:
Public Overrides Function ToString() As String
  Return Name & " (" & Email & ")"
End Function


Form1.vb
Public Class Form1
  Private objCustomers As New ArrayList
  Public Sub CreateCustomer(ByVal firstName As String, ByVal lastName As String, ByVal email As String)
     Dim objNewCustomers As Customer
     objNewCustomers.FirstName = firstName
     objNewCustomers.LastName = lastName
     objNewCustomers.Email = email
     'objNewCustomers.Add(objCustomers)
     lstCustomers.Items.Add(objCustomers)
  End Sub
  Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
     Dim objCustomer As Customer
     objCustomer.FirstName = "Michael"
     objCustomer.LastName = "Dell"
     objCustomer.Email = "mdell@somecompany.com"
     DisplayCustomer(objCustomer)
     CreateCustomer("Darrel", "Hilton", "dhilton@somecompany.com")
     CreateCustomer("Frank", "Peoples", "fpeoples@somecompany.com")
     CreateCustomer("Bill", "Scott", "bscott@somecompany.com")
  End Sub
  Public Sub DisplayCustomer(ByVal customer As Customer)
     txtName.Text = customer.Name
     txtFirstName.Text = customer.FirstName
     txtLastName.Text = customer.LastName
     txtEmail.Text = customer.Email
  End Sub
End Class

Customer.vb
Public Structure Customer
  Public FirstName As String
  Public LastName As String
  Public Email As String
  Public ReadOnly Property Name() As String
     Get
        Return FirstName & " " & LastName
     End Get
  End Property
  Public Overrides Function ToString() As String
     Return Name & " (" & Email & ")"
  End Function
End Structure

Tracey April 30th, 2007 09:53 AM

I discovered a type-o

I guess I had to walk away and do something else in order to clear my mind.

Tracey

Tracey


All times are GMT -4. The time now is 05:47 AM.

Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.