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 = "
[email protected]"
DisplayCustomer(objCustomer)
CreateCustomer("Darrel", "Hilton", "
[email protected]")
CreateCustomer("Frank", "Peoples", "
[email protected]")
CreateCustomer("Bill", "Scott", "
[email protected]")
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