Wrox Programmer Forums
|
BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6
This is the forum to discuss the Wrox book Beginning Visual Basic 2005 by Thearon Willis, Bryan Newsome; ISBN: 9780764574016
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 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 August 8th, 2006, 11:03 AM
Registered User
 
Join Date: Aug 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Page 154 Code Errors

I am having trouble with the code on 154, I am getting two errors:

For [u]DialogResult.Yes </u> I get the folloing error: Access of shared member, constant member,enum member or nested type through an instance; qualifying expression will not be evaluated.

For [u]End Get</u> I get the following error: Property "Selected Customer" Dosen't return a value on all code paths. A null reference exception could occure at run time whn the result is used.

My code follows:


Public Class Form1
    'Form level members
    Private objCustomers As New ArrayList
    Public Sub CreateCustomer(ByVal firstName As String, ByVal lastName As String, ByVal email As String)
        'Declare a customer object
        Dim objNewCustomer As Customer

        'Create the new customer
        objNewCustomer.FirstName = firstName
        objNewCustomer.LastName = lastName
        objNewCustomer.Email = email

        'Add the new customer to the list
        objCustomers.Add(objNewCustomer)

        'Add the new customer to the ListBox control
        lstCustomers.Items.Add(objNewCustomer)
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
        'Create some customer
        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)
        'Display the customer details on the form
        txtFirstName.Text = customer.FirstName
        txtLastName.Text = customer.LastName
        txtEmail.Text = customer.Email
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        'If no customer is selected in the ListBox then...
        If lstCustomers.SelectedIndex = -1 Then

            'Display a message
            MessageBox.Show("You must select a customer to delete,", "Structure Demo")
            'Exit this method
            Exit Sub
        End If
        'Prompt the user to delete the selected customer
        If MessageBox.Show("Are your sure you want to delete " & _
         SelectedCustomer.Name & "?", "Structure Demo", _
         MessageBoxButtons.YesNo, MessageBoxIcon.Question) = _
         DialogResult.Yes Then
            'Get the customer to be deleted
            Dim objCustomerToDelete As Customer = SelectedCustomer

            'Remove the customer from the ArrayList
            objCustomers.Remove(objCustomerToDelete)

            'Remove the customer from the ListBox
            lstCustomers.Items.Remove(objCustomerToDelete)
        End If
    End Sub
    Public ReadOnly Property SelectedCustomer() As Customer
        Get
            If lstCustomers.SelectedIndex <> -1 Then
                'Return the selected customer
                Return lstCustomers.Items(lstCustomers.SelectedIndex)
            End If
        :D
    End Property
End Class
 
Old August 14th, 2006, 08:50 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Please review the errata at http://www.wrox.com/WileyCDA/WroxTit...ew_errata.html concerning the DialogResult.Yes error. The other error concerning End Get is just a warning and can be ignored.

Thearon





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 4 Example Code Errors beckerm13 BOOK: Professional Ajax ISBN: 978-0-471-77778-6 3 September 28th, 2006 03:40 PM
Page 154, revisited with Option Strict On irish_songbird BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 1 September 9th, 2006 07:24 PM
page 154 Begining Visual Basic 2005 fergi BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 2 July 24th, 2006 04:54 PM
done, but with errors on page bubblez Classic ASP Databases 4 September 11th, 2003 03:35 AM





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