Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

FACULTY OF INFORMATION TECHNOLOGY

PROGRAMMING
1ST SEMESTER ASSIGNMENT

Name & Surname: Bwalya Terissa Popopo ICAS No: 402106779

Qualification: BSc IT Semester: 1 Module Name: Programming 511

Date Submitted: 14 May 2021

ASSESSMENT CRITERIA MARK EXAMINER MODERATOR


ALLOCATION MARKS MARKS

MARKS FOR CONTENT


QUESTION ONE 30
QUESTION TWO 30
QUESTION THREE 30
TOTAL MARKS 90
MARKS FOR TECHNICAL ASPECTS
1. TABLE OF CONTENTS 2
2. LAYOUT AND SPELLING 3
3. REFERENCE 5

TOTAL MARKS 10
TOTAL MARKS FOR ASSIGNMENT 100
Examiner’s Comments:

Moderator’s Comments:

Signature of Examiner: Signature of Moderator:

1|Page
Table of Contents
Question 1: .............................................................................................................................................. 3
Question 3: .............................................................................................................................................. 8
Bibliography .......................................................................................................................................... 10

2|Page
Question 1:

Coding:
Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


Try
Dim firstNum As Double = CDbl(ComboBox1.Text)
Dim secondNum As Double = CDbl(ComboBox2.Text)
Dim thirdNum As Double = CDbl(ComboBox3.Text)
Dim fourthNum As Double = CDbl(ComboBox4.Text)

Dim sum1 = firstNum / secondNum * thirdNum


Dim sum2 = fourthNum
Dim sum = sum2 - sum1 + 1

TextBox5.Text = CInt(sum)

Catch ex As System.InvalidCastException
MessageBox.Show("Please enter a number",
"Error")

Console.WriteLine("An unknown error has occured",


"Error")
Catch ex As Exception
MessageBox.Show("An unknown error occurred",
"Error")
End Try

End Sub

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


ComboBox1.Items.Add("10")
ComboBox1.Items.Add("15")
ComboBox1.Items.Add("20")
ComboBox1.Items.Add("25")
ComboBox1.Items.Add("30")
ComboBox1.Items.Add("35")

ComboBox2.Items.Add("10")

3|Page
ComboBox2.Items.Add("15")
ComboBox2.Items.Add("20")
ComboBox2.Items.Add("25")
ComboBox2.Items.Add("30")
ComboBox2.Items.Add("35")

ComboBox3.Items.Add("10")
ComboBox3.Items.Add("15")
ComboBox3.Items.Add("20")
ComboBox3.Items.Add("25")
ComboBox3.Items.Add("30")
ComboBox3.Items.Add("35")

ComboBox4.Items.Add("40")
ComboBox4.Items.Add("40,5")
ComboBox4.Items.Add("41")
ComboBox4.Items.Add("41,5")
ComboBox4.Items.Add("42")
ComboBox4.Items.Add("42,5")
ComboBox4.Items.Add("43")
ComboBox4.Items.Add("43,5")
ComboBox4.Items.Add("44")
ComboBox4.Items.Add("44,5")
ComboBox4.Items.Add("45")
ComboBox4.Items.Add("45,5")
ComboBox4.Items.Add("46")
ComboBox4.Items.Add("46,5")
ComboBox4.Items.Add("47")
ComboBox4.Items.Add("47,5")
ComboBox4.Items.Add("48")
ComboBox4.Items.Add("48,5")
ComboBox4.Items.Add("49")
ComboBox4.Items.Add("49,5")
ComboBox4.Items.Add("50")

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


Me.Close()
End Sub

4|Page
Question 2:

Coding:
Private Sub displayBtn_Click(sender As Object, e As EventArgs) Handles displayBtn.Click

'Validate the form before calculating


If assetTxt.Text.Length.Equals(0) Then
MessageBox.Show("We need the asset cost", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
assetTxt.Focus()
ElseIf salvageTxt.Text.Length.Equals(0) Then
MessageBox.Show("We need the salvage", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
salvageTxt.Focus()
ElseIf lifeCbx.SelectedIndex.Equals(-1) Then
MessageBox.Show("We need useful life", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Else
Dim assetDbl As Double
Double.TryParse(assetTxt.Text, assetDbl)

Dim salvage As Double


Double.TryParse(salvageTxt.Text, salvage)

Dim years As Int32


Int32.TryParse(lifeCbx.SelectedItem.ToString, years)

If assetDbl > 0 And salvage > 0 And years > 0 Then


CalculateDDB(assetDbl, salvage, years)
Else
MessageBox.Show("We need valid values", "Error",
MessageBoxButtons.OK,MessageBoxIcon.Error)
End If

End If
End Sub
Sub CalculateDDB(ByVal asset As Double, ByVal salvageValue As Double, ByVal yearsAs Int32)

Dim depreciationRate As Double = 100 / years

5|Page
Dim ddbalance As Double = 2 * depreciationRate
' Dim values(years - 1) As Double
Dim firstYearValue = asset * (ddbalance / 100)

ddblb.Items.Add("Years" & vbTab & "Depreciation")


ddblb.Items.Add("1" & vbTab & Format(firstYearValue, "0.00"))

Dim totalYears As Int32 = 0

For i As Int32 = 0 To years


' MsgBox(i)
totalYears += i
Next
'MsgBox(totalYears)

Dim sydInitial = asset - salvageValue

sydlb.Items.Add("Years" & vbTab & "Depreciation")


sydlb.Items.Add("1" & vbTab & Format(sydInitial * (years / totalYears), "0.00"))

For i As Int32 = 0 To years - 2


Dim devaluation As Double = (asset - firstYearValue) * (ddbalance / 100)
' values(i) = devaluation
ddblb.Items.Add((i + 2) & vbTab & Format(devaluation, "0.00"))
asset = asset - devaluation
sydlb.Items.Add(i + 2 & vbTab & Format(sydInitial * ((years - (i + 1)) / totalYears),
"0.00"))
Next

End Sub

End Class

Coding:
Public Class Form1

Private Sub exitBtn_Click(sender As Object, e As EventArgs) Handles exitBtn.Click

'Ask Confirmation before existing

Dim result As DialogResult = MessageBox.Show("Do you really want to exit the


application?", _
"Confirm", _
MessageBoxButtons.YesNo)

If (result.Equals(DialogResult.Yes)) Then
Me.Close()
Else

6|Page
End If

End Sub

7|Page
Question 3:

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs)

End Sub

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

Dim font As New Font(lv.Columns(0).ListView.Font, FontStyle.Bold)


lv.Columns(0).ListView.Font = font
Dim data(,) As String = New String(,) {{"1", "120,000", "90,000", "65,000"},
{"2", "190,000", "85,000", "64,000"}, {"3", "175,000", "64,000", "71,000"}, {"4",
"188,000", "83,000", "67,000"}, {"5", "125,000", "87,000", "65,000"}, {"6", "163,000",
"80,000", "64,000"}}

Dim month1() As Integer = New Integer() {120000, 90000, 65000}


Dim month2() As Integer = New Integer() {190000, 85000, 64000}
Dim month3() As Integer = New Integer() {175000, 64000, 71000}
Dim month4() As Integer = New Integer() {188000, 83000, 67000}
Dim month5() As Integer = New Integer() {125000, 87000, 65000}
Dim month6() As Integer = New Integer() {163000, 80000, 64000}

Dim months() As Object = {month1, month2, month3, month4, month5, month6}

For i As Integer = 0 To 5
Dim LI As New ListViewItem
'LI.SubItems.Add(data(0, 0))

Dim m() As Integer = months(i)

For j As Integer = 0 To 3
If j = 0 Then
LI.Text = data(i, j)
Else
Dim total = m.Sum()
Console.WriteLine(m.Sum)
Console.WriteLine("First one" & m(j - 1) / total)
Dim perc = Format(m(j - 1) / total, " (0.00%) ")

LI.SubItems.Add(data(i, j) & perc)

8|Page
Dim ff As New Font(LI.SubItems(0).Font, FontStyle.Regular)
LI.SubItems(0).Font = ff
End If

Next
lv.Items.Add(LI)
'lv.Items(i).ListView.Font = New Font(lv.Items(i).ListView.Font,
FontStyle.Bold)
' lv.Items(0).SubItems(0).Text = data(0).

Next

'ListBox1.Items.Add("Month" & vbTab & vbTab & "Kwazulu-Natal sales(R)" & vbTab
& vbTab & "Gauteng sales(R)" & vbTab & vbTab & "Western cape sales(R)")
'ListBox1.Items.Add("1" & vbTab & vbTab & vbTab & "120,000" & vbTab & vbTab &
vbTab & "90,000" & vbTab & vbTab & vbTab & "65,000")
'ListBox1.Items.Add("2" & vbTab & vbTab & vbTab & "190,000" & vbTab & vbTab &
vbTab & "85,000" & vbTab & vbTab & vbTab & "64,000")
'ListBox1.Items.Add("3" & vbTab & vbTab & vbTab & "175,000" & vbTab & vbTab &
vbTab & "64,000" & vbTab & vbTab & vbTab & "71,000")
'ListBox1.Items.Add("4" & vbTab & vbTab & vbTab & "188,000" & vbTab & vbTab &
vbTab & "83,000" & vbTab & vbTab & vbTab & "67,000")
'ListBox1.Items.Add("5" & vbTab & vbTab & vbTab & "125,000" & vbTab & vbTab &
vbTab & "87,000" & vbTab & vbTab & vbTab & "65,000")
'ListBox1.Items.Add("6" & vbTab & vbTab & vbTab & "163,000" & vbTab & vbTab &
vbTab & "80,000" & vbTab & vbTab & vbTab & "64,000")
End Sub

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


lv.SelectedIndexChanged

End Sub
End Class
(Kiong, 2010)

9|Page
Bibliography
Kiong, D. V. (2010, March). VBTutor. Retrieved from
https://www.vbtutor.net/vb2013/vb2013tutor.html

10 | P a g e

You might also like