Results 1 to 8 of 8

Thread: [RESOLVED] Derive from the generic List class

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Resolved [RESOLVED] Derive from the generic List class

    Can someone tell me if Im on the right track and what Im missing??

    My instructions are:

    Add a new public class named GroceryBasket to the project.

    1. Derive from the generic List class.
    2. Ensure that only GroceryItem objects are stored as items.

    Here is my GroceryBasket Code:

    Code:
    Public Class GroceryBasket
        Inherits List(Of GroceryItem)
    End Clas
    Did I write that right?? If not how do I??


    Heres my GroceryItem Code:

    Code:
    Public Class GroceryItem
        Private mScanNumber As Integer
        Public ReadOnly Property ScanNumber As Integer
            Get
                Return mScanNumber
            End Get
        End Property
        Private mBrandName As String
        Public Property BrandName As String
            Get
                Return mBrandName
            End Get
            Set(value As String)
                mBrandName = value
            End Set
        End Property
        Private mDescription As String
        Public Property Description As String
            Get
                Return mDescription
            End Get
            Set(value As String)
                mDescription = value
            End Set
        End Property
        Private mPrice As Double
        Public Property Price As Double
            Get
                Return mPrice
            End Get
            Set(value As Double)
                If value > 0 Then
                    mPrice = value
                End If
            End Set
        End Property
        Private mAisle As String
        Public Property Aisle As String
            Get
                Return mAisle
            End Get
            Set(value As String)
                mAisle = value
            End Set
        End Property
    
        Public Sub New(MscanNumber As Integer, brandName As String, price As Double)
            Me.mScanNumber = ScanNumber
            Me.BrandName = brandName
            Me.Price = price
        End Sub
    End Class



    I already did this part: Add the following variable declaration to the Main module: Friend basket As New GroceryBasket

    Heres my Main Code:

    Code:
    Module Main
        Friend blnLoggedIn As Boolean
        Dim arrUsernames() As String = {"Admin", "Clerk", "Manager"}
        Dim arrPasswords() As String = {"P@ssword", "pa$$word", "passw0rd"}
        Dim userIndex As Integer
        Friend basket As New GroceryBasket


    I dont understand how to do this part either??

    Note: You can add code to the btnLogin_Click event handler procedure to instantiate the GroceryItem class and add multiple objects to the GroceryBasket variable. Make sure you either remove or comment out this code after testing.

    Here is my LoginForm with the btnlogin_Click handler:

    Code:
    Public Class LoginForm
        Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
            Try
                Login(txtUsername.Text, txtPassword.Text)
            Catch ex As LoginException
                MessageBox.Show(“Incorrect password.”)
            End Try
            If Main.blnLoggedIn Then
                MessageBox.Show(“Thank you for logging in, “ & txtUsername.Text, “Logged In.”)
                Me.Close()
            End If
    
        End Sub
    
        Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
            Application.Exit()
        End Sub
    End Class
    Last edited by EmilyM1105; Feb 2nd, 2018 at 02:56 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width