0% found this document useful (1 vote)
2K views

Lab Exercises For Visual Basic 6.0

This document contains information about two computer programming lab exercises - a quadratic equation graphing program and a depreciation calculator program. The quadratic equation graphing program allows users to input coefficients a, b, c and plots the quadratic function f(x)=ax^2 + bx + c on a picture box. It uses a For-Next loop and Pset method to draw the graph by increments. The depreciation calculator program allows users to input initial cost, salvage value, asset life, and depreciation period to calculate depreciation amount using the DDB function. It displays the depreciation amount on a label when the command button is clicked. Both programs provide useful tools for students and

Uploaded by

oliver wekesa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
2K views

Lab Exercises For Visual Basic 6.0

This document contains information about two computer programming lab exercises - a quadratic equation graphing program and a depreciation calculator program. The quadratic equation graphing program allows users to input coefficients a, b, c and plots the quadratic function f(x)=ax^2 + bx + c on a picture box. It uses a For-Next loop and Pset method to draw the graph by increments. The depreciation calculator program allows users to input initial cost, salvage value, asset life, and depreciation period to calculate depreciation amount using the DDB function. It displays the depreciation amount on a label when the command button is clicked. Both programs provide useful tools for students and

Uploaded by

oliver wekesa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

ABMI 2224-COMPUTER

PROGRAMMING FOR BUSINESS


Lab Exercises

Dismas Ombuya
Technical University Of Kenya

This is a program that can plot graphs for quadratic


functions. The general format of a quadratic
equation is f(x)= ax2+bx+c , where a, b and c are
constant. - See more at:
This program employs a picture box as the plot
area and three text boxes to obtain the values of the
coefficients a, b, c of the quadratic equation from the
users. We also need to modify the scale factor in the
properties windows of the picture box. We are using
a scale of 0.5 cm to represent 1 unit . -

Besides, we need to make some transformation as the


coordinates in VB start from top left but we want it to start from
the middle. We can use the Pset method to draw the graph using
a very small increment. Pset is a method that draws a dot on the
screen, the syntax is - See more at:

Pset(x,y), color

Where (x,y) is the coordinates of the dot and


color is the color of the dot. The default color
is black. Using the For Next loop together
with Pset, we can draw a line on the screen.
This program is useful for high school
students and mathematics teachers.

The Interface

The Code

Private Sub cmd_draw_Click()


Dim a, b, c As Integer
Dim w, v As Single
a = Val(txt_a.Text)
b = Val(txt_b.Text)
c = Val(txt_c.Text)
'Using a scale of 0.5 cm to represent i unit to draw the graph
' Need to make some transformation as the coordinates in VB
start from top left
For w = 0 To 10 Step 0.001

v = a * (5 - w) ^ 2 - b * (5 - w) + c
pic_graph.PSet (w, 5 - v)
Next w
End Sub

Private Sub Command1_Click()


pic_graph.Cls
txt_a.Text = ""
txt_b.Text = ""
txt_c.Text = ""
End Sub

Program Two:Depreciation Calculator


Depreciation means a reduction in the value of an asset with the
passage of time. Depreciation is computed based on the initial
purchase price or initial cost, number of years where depreciation is
calculated, salvage value at the end of the depreciation period, and the
asset's life span.
Depreciation is an important element in the management of a
company's assets. With proper and accurate calculation of depreciation,
a company can benefit from the tax advantage.

In Visual Basic, The syntax of the depreciation function is


DDB(Cost,Salvage,Life, Period)
Cost=Initial cost
Salvage=Salvage value
Life=Asset's life span
Period=Depreciation period

In this program, we need to insert four text boxes for the user to
enter the initial cost, the salvage value, the asset's life and the
period of depreciation. Besides that, insert a label to display the
amount of depreciation and a command button to compute the
depreciation.

Interface

The Code
Private Sub Command1_Click()
Dim Int_Cost, Sal_Value, Asset_Life, Deperiod, Depre_Amt As Double
Int_Cost = Val(Txt_Cost.Text)
Sal_Value = Val(Txt_Salvage.Text)

Asset_Life = Val(Txt_Life.Text)
Deperiod = Val(Txt_Period.Text)
Depre_Amt = DDB(Int_Cost, Sal_Value, Asset_Life, Deperiod)
Lbl_Dpre.Caption = Format(Depre_Amt, "$###,###,000.00")
End Su

You might also like