0% found this document useful (0 votes)
256 views15 pages

Callyn Naidoo - Programing 511

The document describes 3 programming assignments that involve building GUI interfaces and writing code in Visual Basic. Question 1 involves building a GUI to calculate rolls of material needed based on input dimensions. Question 2 builds a GUI to calculate depreciation amounts over years using the double declining balance and straight line methods. Question 3 builds a GUI to analyze sales data stored in an array, calculate totals by region, and display percentages. The document provides code snippets and descriptions of the GUI and functionality for each question.

Uploaded by

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

Callyn Naidoo - Programing 511

The document describes 3 programming assignments that involve building GUI interfaces and writing code in Visual Basic. Question 1 involves building a GUI to calculate rolls of material needed based on input dimensions. Question 2 builds a GUI to calculate depreciation amounts over years using the double declining balance and straight line methods. Question 3 builds a GUI to analyze sales data stored in an array, calculate totals by region, and display percentages. The document provides code snippets and descriptions of the GUI and functionality for each question.

Uploaded by

Deep Insanityx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

1

Callyn Naidoo

Templet

Assignment
3

Contents
Question One:.......................................................................................................................................4
GUI:....................................................................................................................................................4
CODE:................................................................................................................................................4
Running Program:..............................................................................................................................5
Drop down list:..................................................................................................................................6
Question Two:.......................................................................................................................................7
GUI:....................................................................................................................................................7
CODE:................................................................................................................................................7
Running Program:..............................................................................................................................9
Question Three:...................................................................................................................................10
GUI:..................................................................................................................................................10
CODE:...............................................................................................................................................10
Running Program:............................................................................................................................14
4

Question One:
GUI:

CODE:
Public Class Form1

'variable declaration

Dim nlength, nwidth, nheight As Integer

Dim ntotal, nrollcov As Double

Private Sub btnexit_Click(sender As Object, e As EventArgs) Handles btnexit.Click

'closing form

Me.Close()

End Sub
5

Private Sub btncalculate_Click(sender As Object, e As EventArgs) Handles


btncalculate.Click

'getting values from comboboxs

nlength = CInt(cmblength.Text)

nwidth = CInt(cmbwidth.Text)

nheight = CInt(cmbheight.Text)

nrollcov = CDbl(cmbrollcov.Text)

'calculation of rolls required

ntotal = ((nlength * nheight) + (nwidth * nheight)) * 2

ntotal = ntotal / nrollcov

'displaying answer

txtsingleroll.Text = CStr(Math.Ceiling(ntotal))

End Sub

End Class

Running Program:
6

Drop down list:


7

Question Two:
GUI:

CODE:
Public Class Form1
8

'Variable declaration

Dim nassestcost, nsalvagevalue, ntotalddb, ntotalsyd As Double

Dim nusefullife, nperiod As Integer

Private Sub btndisplay_Click(sender As Object, e As EventArgs) Handles btndisplay.Click

'Getting values from textbox

nassestcost = CDbl(txtassest.Text)

nsalvagevalue = CDbl(txtsalvage.Text)

'Getting Value from combo box

nusefullife = CInt(cmbuseful.Text)

'Displayig headings in listbox

ListBox1.Items.Add("Year" + vbTab + "Depreciation")

ListBox2.Items.Add("Year" + vbTab + "Depreciation")

'Loop begins

For nperiod = 1 To nusefullife

'Calculation

ntotalddb = Math.Round(Financial.DDB(nassestcost, nsalvagevalue, nusefullife,


nperiod), 2)

ntotalsyd = Math.Round(Financial.SYD(nassestcost, nsalvagevalue, nusefullife,


nperiod), 2)

'Display Answers on listbox

ListBox1.Items.Add(CStr(nperiod) + vbTab + CStr(FormatNumber(ntotalddb, 2)))

ListBox2.Items.Add(CStr(nperiod) + vbTab + CStr(FormatNumber(ntotalsyd, 2)))

'Loop ends

Next

End Sub

Private Sub btnexit_Click(sender As Object, e As EventArgs) Handles btnexit.Click


9

'Closing Form

Me.Close()

End Sub

End Class

Running Program:
10
11

Question Three:
GUI:

CODE:
Public Class Form1

'Array declaration

Dim salesarray(6, 3) As String

'Variable declaration

Dim getvaluekzn, getvalueng, getvaluewc As String

Dim ntotalsales, nprecentkzn, nprecetg, nprecentwc, nkzntotal, ngtotal, nwctotal, counter,


nloopcontrol As Integer

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


12

End Sub

Private Sub btndisplay_Click(sender As Object, e As EventArgs) Handles btndisplay.Click

'Array value

salesarray(1, 1) = 120000

salesarray(2, 1) = 190000

salesarray(3, 1) = 175000

salesarray(4, 1) = 188000

salesarray(5, 1) = 125000

salesarray(6, 1) = 163000

salesarray(1, 2) = 90000

salesarray(2, 2) = 85000

salesarray(3, 2) = 80000

salesarray(4, 2) = 83000

salesarray(5, 2) = 87000

salesarray(6, 2) = 80000

salesarray(1, 3) = 65000

salesarray(2, 3) = 64000

salesarray(3, 3) = 71000

salesarray(4, 3) = 67000

salesarray(5, 3) = 65000

salesarray(6, 3) = 64000

'Displaying heading for sales


13

ListBox1.Items.Add("Month" + vbTab + "Kwazulu-Natal sales (R)" + vbTab + "Gauteng


sales (R)" + vbTab + vbTab + "Western cape sales (R)")

'Setting Values for loop to 0

counter = 0

nkzntotal = 0

ngtotal = 0

nwctotal = 0

nloopcontrol = 0

'Do until loop begins

Do Until nloopcontrol = 6

'Counter keeps track of vlaues to be place in getvalues

counter = counter + 1

'Getting values from array

getvaluekzn = salesarray(counter, 1)

getvalueng = salesarray(counter, 2)

getvaluewc = salesarray(counter, 3)

'Calculating total sales for each region

nkzntotal = nkzntotal + CInt(getvaluekzn)

ngtotal = ngtotal + CInt(getvalueng)

nwctotal = nwctotal + CInt(getvaluewc)

'Displaying in list box the values from array

ListBox1.Items.Add(CStr(counter) + vbTab + getvaluekzn + vbTab + vbTab + vbTab +


getvalueng + vbTab + vbTab + vbTab + getvaluewc)

'Controls the loop to end after getting all the value out of the array

nloopcontrol = nloopcontrol + 1

Loop

'Calculating the total sales made by all regions


14

ntotalsales = nkzntotal + ngtotal + nwctotal

'Calculating the precentages of each region

nprecentkzn = (nkzntotal / ntotalsales) * 100

nprecetg = (ngtotal / ntotalsales) * 100

nprecentwc = (nwctotal / ntotalsales) * 100

'Displaying total sales made by all regions

ListBox2.Items.Add("Total Sales :" + vbTab + "R" + CStr(ntotalsales))

'Displaying precentages of each region

ListBox2.Items.Add("Kwazulu-Natal :" + vbTab + CStr(nprecentkzn) + "%")

ListBox2.Items.Add("Gauteng :" + vbTab + CStr(nprecetg) + "%")

ListBox2.Items.Add("Western cape :" + vbTab + CStr(nprecentwc) + "%")

End Sub

Private Sub btnexit_Click(sender As Object, e As EventArgs) Handles btnexit.Click

'Closing form

Me.Close()

End Sub

End Class
15

Running Program:

You might also like