You are on page 1of 4

NAME: MAKAFUI DIVINE GATI-KWASHIE

INDEX: 10098259
COURSE CODE: BITM301
COURSE TITLE: PROGRAMMING
SESSION: MORNING

ASSIGNMENT 3
The image below is the user interface of my calculator application which I named
Makafui Divine Gati-Kwashie. I created a textbox and 17 buttons which include
numbers from 0-9, operations such as addition (+), subtraction (-), multiplication (*)
and division (/) also a dot(.) to interpret decimal values, an equal to sign (=) and a
clear(C) button for clearing text in the textbox.

INPUT

After the design process, I proceeded to the form.vb where I was able to write the
codes for the various buttons and textbox.

Before my program will be able to run, I declared some variables with my initials
which is shown below:
Public Class Form1

Dim MDGKfirstnum As Decimal


Dim MDGKsecondnum As Decimal
Dim MDGKoperations As Integer
Dim MDGKoperator_selector As Boolean = False

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


End Sub
I proceeded to write specific action for all buttons. In the code, I declared that when
a button is clicked, the number on the button is displayed in the textbox. This is
illustrated below:

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


Button5.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "1"
Else
TextBox1.Text = "1"
End If
End Sub
The above process is repeated for all numbers between 1-9

PROCESSES AND OUTPUT

When a user inputs two numbers i.e., MDGKfirstnum and MDGKsecondnum, and uses an
operation (+, -, *, /), an answer should be provided in the textbox. Example
MDGKfirstnum + MDGKsecondnum = output

This is further explained below:

Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click


MDGKfirstnum = TextBox1.Text
TextBox1.Text = "0"
MDGKoperator_selector = True
MDGKoperations = 1 ' = +
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click


MDGKfirstnum = TextBox1.Text
TextBox1.Text = "0"
MDGKoperator_selector = True
MDGKoperations = 2 ' = -
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


MDGKfirstnum = TextBox1.Text
TextBox1.Text = "0"
MDGKoperator_selector = True
MDGKoperations = 3 ' = *
End Sub

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


MDGKfirstnum = TextBox1.Text
TextBox1.Text = "0"
MDGKoperator_selector = True
MDGKoperations = 4 ' /
End Sub
Private Sub Button16_Click(sender As Object, e As EventArgs) Handles
Button16.Click
If MDGKoperator_selector = True Then
MDGKsecondnum = TextBox1.Text
If MDGKoperations = 1 Then
TextBox1.Text = MDGKfirstnum + MDGKsecondnum
ElseIf MDGKoperations = 2 Then
TextBox1.Text = MDGKfirstnum - MDGKsecondnum
ElseIf MDGKoperations = 3 Then
TextBox1.Text = MDGKfirstnum * MDGKsecondnum
Else
If MDGKsecondnum = 0 Then
TextBox1.Text = "ERROR !"
Else
TextBox1.Text = MDGKfirstnum / MDGKsecondnum
End If
End If
MDGKoperator_selector = False
End If
End Sub
End Class

You might also like