Translate To Preferred Language

Search Obioku's Thoughts

Please Read Today's Featured Post

Things I Would Like To Happen Soon

For all those who believe in speaking ideas into existence and prayer in the universe will return to a person.  I simply want to write a lis...

Template for Inventory Depreciation in Visual Basic (some bugs may occur)

Option Strict On

Public Class frmDepreciation
    'Create Variables
    Private intLifeSpan As Integer = 5I
    Public Shared intArray As Integer = 7I
    Public Shared strInventory(intArray) As String
    Private strID(intArray) As String
    Private decInitPrice(intArray) As Decimal
    Private intQuantity(intArray) As Integer


    Private Sub frmDepreciation_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'Initialize I/O file
        Dim objReader As IO.StreamReader
        Dim strFile As String = "H:\My Documents\Visual Studio 2012\Projects\Depreciation\inventory.txt"

        'Declare variables
        Dim intCount As Integer = 0I
        'Dim intFill As Integer
        Dim strError As String = "The file is not available. Restart when the file is available."
        Dim frmList As New frmDisplay


            'Verify file
            If IO.File.Exists(strFile) Then
            objReader = IO.File.OpenText(strFile)

            Try
                'Input file a line at a time
                Do While objReader.Peek <> -1
                    'shows message box when program begins and returns from second form

                    strInventory(intCount) = objReader.ReadLine()
                    strID(intCount) = objReader.ReadLine()
                    decInitPrice(intCount) = Convert.ToDecimal(objReader.ReadLine())
                    intQuantity(intCount) = Convert.ToInt32(objReader.ReadLine())
                    'frmList.lstDisplay.Items.Add(strInventory(intCount))
                    lstInventory.Items.Add(strID(intCount))
                    intCount += 1

                Loop

            Catch ex As IndexOutOfRangeException
                MsgBox("Array is out of bounds", , "Range is not correct")
            End Try

            objReader.Close()

            'Please inventory IDs in listbox
            ' For intFill = 0 To (strID.Length - 1)
            'lstInventory.Items.Add(strID(intFill))
            'Next

        Else
            MsgBox(strError, , "Error")
            Close()

        End If

    End Sub

    Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
        'Declare variables
        Dim intSelect As Integer

        'If listbox and groupbox are chosen procedure will be called
        If lstInventory.SelectedIndex >= 0 Then
            intSelect = lstInventory.SelectedIndex
            If rbStraight.Checked Then
                StraightDep(intSelect)
            ElseIf rbDecline.Checked Then
                DeclineDep(intSelect)
            Else
                MsgBox("Select a Depreciation Method", , "Missing Selection")
            End If
        Else
            MsgBox("Select an Inventory Item ID", , "Missing Selection")
        End If
    End Sub

    Private Sub StraightDep(ByVal intID As Integer)
        'Calculate and display straight line version of depreciation

        'Declare variables
        Dim intPresentY As Integer
        Dim decPresentV As Decimal = 0D
        Dim decDep As Decimal
        Dim decTotal As Decimal = 0D

        'Use procedure to make objects visible
        MakeObjectsVisible()

        lblItem.Text = "The depreciation of the item: " & strInventory(intID) & Environment.NewLine _
            & "Quantity: " & intQuantity(intID).ToString()

        'Create formula for depreciation
        decDep = decInitPrice(intID) / intLifeSpan
        decPresentV = decInitPrice(intID)

        'Loop repeat for lifespan
        For intPresentY = 1 To intLifeSpan
            decTotal += decDep
            lstPreYear.Items.Add(intPresentY.ToString())
            lstPreVal.Items.Add(decPresentV.ToString("C"))
            lstYearDep.Items.Add(decDep.ToString("C"))
            lstTotalDep.Items.Add(decTotal.ToString("C"))
            decPresentV -= decDep
        Next
    End Sub

    Private Sub DeclineDep(ByVal intID As Integer)
        'Calculate and display straight line version of depreciation

        'Declare variables
        Dim intPresentY As Integer
        Dim decPresentV As Decimal = 0D
        Dim decDep As Decimal
        Dim decTotal As Decimal = 0D

        'Use procedure to make objects visible
        MakeObjectsVisible()

        lblItem.Text = "The depreciation of the item: " & strInventory(intID) & Environment.NewLine _
            & "Quantity: " & intQuantity(intID).ToString()
        decPresentV = decInitPrice(intID)

        'Create formula for depreciation
        decDep = (decPresentV * 2D) / intLifeSpan

        'Loop repeat for lifespan
        For intPresentY = 1 To intLifeSpan
            decTotal += decDep
            lstPreYear.Items.Add(intPresentY.ToString())
            lstPreVal.Items.Add(decPresentV.ToString("C"))
            lstYearDep.Items.Add(decDep.ToString("C"))
            lstTotalDep.Items.Add(decTotal.ToString("C"))
            decPresentV -= decDep
        Next
    End Sub

    Private Sub MakeObjectsVisible()
        'Shows all labels and empties listboxes
        lblItem.Visible = True

        lblPreVal.Visible = True
        lstPreVal.Items.Clear()
        lstPreVal.Visible = True

        lblPreYear.Visible = True
        lstPreYear.Items.Clear()
        lstPreYear.Visible = True

        lblTotalDep.Visible = True
        lstTotalDep.Items.Clear()
        lstTotalDep.Visible = True

        lblYearDep.Visible = True
        lstYearDep.Items.Clear()
        lstYearDep.Visible = True
    End Sub

 
    Private Sub mnuDisplay_Click(sender As Object, e As EventArgs) Handles mnuDisplay.Click
        'Display inventory menu option shows application's second form
        Hide()
        frmDisplay.ShowDialog()
    End Sub


    Private Sub mnuClear_Click(sender As Object, e As EventArgs) Handles mnuClear.Click
        'Resets form
        lstInventory.SelectedIndex = -1
        rbStraight.Checked = False
        rbDecline.Checked = False

        'Hides all labels and clears listboxes
        lblItem.Visible = False

        lblPreVal.Visible = False
        lstPreVal.Items.Clear()
        lstPreVal.Visible = False

        lblPreYear.Visible = False
        lstPreYear.Items.Clear()
        lstPreYear.Visible = False

        lblTotalDep.Visible = False
        lstTotalDep.Items.Clear()
        lstTotalDep.Visible = False

        lblYearDep.Visible = False
        lstYearDep.Items.Clear()
        lstYearDep.Visible = False
    End Sub


    Private Sub mnuExitDep_Click(sender As Object, e As EventArgs) Handles mnuExitDep.Click
        'Closes application
        Application.Exit()
    End Sub
End Class

No comments:

Post a Comment

Thank you very much for viewing this entry and I hope you are able to return soon to continue to enjoy more of the site.
Please share your thoughts in the comment section.
Be blessed and enjoy life!