0% found this document useful (0 votes)
31 views1 page

Complete-Reference-Vb Net 5

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views1 page

Complete-Reference-Vb Net 5

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Structures

Note The code for the above Complex structure is the ComplexTypes project in the Vb7cr solution.
Here's another illustration of a financial structure encapsulating a financial function found in numerous
function libraries, like those in Microsoft Excel®. The following structure implements methods for computing
financial information. I have just shown an attempt at the straight−line Double−Declining Balance formula
(book−value * 2/useful life), which computes depreciation on an asset for a number of years.

The DDB function is computed iteratively. In the following code the book value starts out at a value minus
the current salvage value (what the item can be sold for on Ebay today). The methods respectively return the
amount the book value decreased in the specified period in its useful life and the amount of depreciation to
report.

Imports System
Public Structure Accounting
Dim cost, salvage As Double
Dim life, period As Integer
Dim factor As Decimal

Public Sub New(ByVal rcost As Double, ByVal rsalvage As Double, _


ByVal rlife As Integer, ByVal rperiod As Integer, _
Optional ByVal rfactor As Decimal = 2)
cost = rcost
salvage = rsalvage
life = rlife
period = rperiod
factor = rfactor
End Sub

ReadOnly Property DDBValue()


Get
Dim book As Double = cost salvage
Dim deprec As Double
Dim year As Integer = period
While year > 1
deprec = book * factor / life
book = book deprec
year −= 1
End While
Return book
End Get
End Property

ReadOnly Property DDBDepreciation()


Get
Dim book As Double = cost salvage
Dim deprec As Double
Dim year As Integer = period
While year >= 1
deprec = book * factor / life
book = book deprec
year −= 1
End While
Return deprec
End Get
End Property
End Structure

The Accounting value type can be used as demonstrated here. The following code:

243

You might also like