Depreciation Calculator in Visual Basic

Obioku Obotette
3 min readOct 22, 2020

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

--

--

Obioku Obotette
0 Followers

Trying to introduce myself in a new forum with hopeful expectations!