Skip to main content

Inventory in VB.NET

Create the Inventory class. This class represents the collection of product object. It has following members: code, description, price and quantity on hand. Create a property to get the product with the specified code. Create a method to add the product to the collection of products.
Inventory.vb
Public Class inventory
    Dim code, price, qun As Integer
    Dim desc As String
    Property pcode() As Integer
        Get
            Return code
        End Get
        Set(ByVal value As Integer)
            code = value
        End Set
    End Property
    Property pprice() As Integer
        Get
            Return price
        End Get
        Set(ByVal value As Integer)
            price = value
        End Set
    End Property
    Property pqun() As Integer
        Get
            Return qun
        End Get
        Set(ByVal value As Integer)
            qun = value
        End Set
    End Property
    Property pdesc() As String
        Get
            Return desc
        End Get
        Set(ByVal value As String)
            desc = value
        End Set
    End Property
End Class
Form1.vb
Public Class Form1
    Dim ProductList(10) As inventory
    Dim c, p, q As Integer
    Dim d As String
    Dim i As Integer = 0
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        c = InputBox("Product Code")
        d = InputBox("Product Description")
        p = InputBox("Product Price")
        q = InputBox("Product Quantity")
        ProductList(i) = New inventory() With {.pcode = c, .pdesc = d, .pprice = p, .pqun = q}
        i += 1
        ComboBox1.Items.Add(c)
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        For k As Integer = 0 To i
            If ProductList(k).pcode = Val(ComboBox1.Text) Then
                TextBox1.Text = ProductList(k).pdesc
                TextBox2.Text = ProductList(k).pprice
                TextBox3.Text = ProductList(k).pqun
                k = i
            End If
        Next
    End Sub
End Class
DESIGNING








Comments