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 May 26th, 2006, 01:24 PM
Registered User
 
Join Date: May 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default chapter 5, pg 154

Ok, so i have been following along with the examples.... When i enter this:
Code:
    
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 Sub
        End If

        If MessageBox.Show("Are you sure you want to delete " & SelectedCustomer.Name & "?", "Structure Demo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then

            'Get the customer object to be deleted
            Dim objCustomerToDelete As Customer = SelectedCustomer

            'Remove the customer from the array list
            objCustomers.Remove(objCustomerToDelete)

            'Remove the customer from the listBox
            lstCustomers.Items.Remove(objCustomerToDelete)
        End If
    End Sub

    Public ReadOnly Property SelectedCustomer() As String
        Get
            If lstCustomers.SelectedIndex <> -1 Then
                Return lstCustomers.Items(lstCustomers.SelectedIndex)
            End If
        End Get
    End Property
I get 2 errors and 1 warning.

The errors are:
'Name' is not a member of 'String'
which points to this line:
Code:
If MessageBox.Show("Are you sure you want to delete " & SelectedCustomer.Name & "?", "Structure Demo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Value of type 'String' cannot be converted to 'StructureDemo.Customer'
Which doesn't like this line
Code:
Dim objCustomerToDelete As Customer = SelectedCustomer
The warning is:
Property 'SelectedCustomer' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.

any thoughts?
 
Old May 26th, 2006, 01:30 PM
Registered User
 
Join Date: May 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i'm sorry, dumb day. keep looking and not seeing. then you see. the selectedcustomer property should return a customer not a string....jeez

 
Old May 1st, 2007, 02:50 PM
Authorized User
 
Join Date: Apr 2007
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
Default

VS2005 states that the following will not be evauluated: ...) = DialogResult.Yes Then...
'suggested chg from: If MessageBox.Show(... = DialogResult.Yes ...
'suggested chg to : If MessageBox.Show(... = Windows.Forms.DialogResult.Yes ...

from:
If MessageBox.Show("Are you sure you want to delete " & SelectedCustomer.Name & "?", "Structure Demo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then

to:
If MessageBox.Show("Are you sure you want to delete " & SelectedCustomer.Name & "?", "Structure Demo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then

Just FYI
 
Old May 1st, 2007, 03:08 PM
Authorized User
 
Join Date: Apr 2007
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Is there a solution to the following: warning BC42107: Property 'SelectedCustomer' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.

Public ReadOnly Property SelectedCustomer() As Customer
   Get
      If lstCustomers.SelectedIndex <> -1 Then
         Return objCustomers(lstCustomers.SelectedIndex)
      End If
   End Get
End Property





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 3 pg 95 al2000 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 2 August 4th, 2008 09:18 PM
Chapter 4 Pg 117 Try It Out workib ASP.NET 3.5 Basics 1 April 7th, 2008 12:49 AM
<CustomAssemblies> Missing (Chapter 5 p 154) jmurdock BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 June 16th, 2004 02:44 PM
Chapter 4 pg 131 cpkaiser BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 3 May 2nd, 2004 01:50 PM





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