0% found this document useful (0 votes)
34 views

CALCULATORVBNET

The document contains code for a basic calculator application with 18 buttons and 1 textbox. Each button click handler appends the corresponding number to the textbox or sets the initial number if the textbox is empty. Additional buttons are included for arithmetic operations which store the first number, clear the textbox, and set the operation type. The equals button performs the calculation and displays the result.

Uploaded by

Raym Puto
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)
34 views

CALCULATORVBNET

The document contains code for a basic calculator application with 18 buttons and 1 textbox. Each button click handler appends the corresponding number to the textbox or sets the initial number if the textbox is empty. Additional buttons are included for arithmetic operations which store the first number, clear the textbox, and set the operation type. The equals button performs the calculation and displays the result.

Uploaded by

Raym Puto
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/ 6

' 18 buttons

' 1 textbox

Public Class Form1

Dim FirstNum As Decimal

Dim SecondNum As Decimal

Dim operations As Integer

Dim o_s As Boolean = False

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

If TextBox1.Text <> "0" Then

TextBox1.Text += "1"

Else

TextBox1.Text = "1"

End If

End Sub

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

If TextBox1.Text <> "0" Then

TextBox1.Text += "2"

Else

TextBox1.Text = "2"

End If

End Sub

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

If TextBox1.Text <> "0" Then

TextBox1.Text += "3"

Else

TextBox1.Text = "3"
End If

End Sub

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

If TextBox1.Text <> "0" Then

TextBox1.Text += "4"

Else

TextBox1.Text = "4"

End If

End Sub

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

If TextBox1.Text <> "0" Then

TextBox1.Text += "5"

Else

TextBox1.Text = "5"

End If

End Sub

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click

If TextBox1.Text <> "0" Then

TextBox1.Text += "6"

Else

TextBox1.Text = "6"

End If

End Sub

Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click

If TextBox1.Text <> "0" Then


TextBox1.Text += "7"

Else

TextBox1.Text = "7"

End If

End Sub

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

If TextBox1.Text <> "0" Then

TextBox1.Text += "8"

Else

TextBox1.Text = "8"

End If

End Sub

Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click

If TextBox1.Text <> "0" Then

TextBox1.Text += "9"

Else

TextBox1.Text = "9"

End If

End Sub

Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click

If TextBox1.Text <> "0" Then

TextBox1.Text += "0"

Else

TextBox1.Text = "0"

End If

End Sub

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


If TextBox1.Text <> "0" Then

TextBox1.Text += "."

Else

TextBox1.Text = "."

End If

End Sub

Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click

FirstNum = TextBox1.Text

TextBox1.Text = "0"

o_s = True

operations = 1 ' +

End Sub

Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click

FirstNum = TextBox1.Text

TextBox1.Text = "0"

o_s = True

operations = 2 ' -

End Sub

Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click

FirstNum = TextBox1.Text

TextBox1.Text = "0"

o_s = True

operations = 3 ' *

End Sub

Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click


FirstNum = TextBox1.Text

TextBox1.Text = "0"

o_s = True

operations = 4 ' /

End Sub

Private Sub Button16_Click(sender As Object, e As EventArgs) Handles Button16.Click

Dim messbox As String

If o_s = True Then

SecondNum = TextBox1.Text

If operations = 1 Then

TextBox1.Text = FirstNum + SecondNum

messbox = Str(TextBox1.Text)

MessageBox.Show(messbox)

ElseIf operations = 2 Then

TextBox1.Text = FirstNum - SecondNum

messbox = Str(TextBox1.Text)

MessageBox.Show(messbox)

ElseIf operations = 3 Then

TextBox1.Text = FirstNum * SecondNum

messbox = Str(TextBox1.Text)

MessageBox.Show(messbox)

ElseIf operations = 4 Then

If SecondNum <> 0 Then

TextBox1.Text = FirstNum / SecondNum

messbox = Str(TextBox1.Text)

MessageBox.Show(messbox)
Else

MessageBox.Show("Error: Division by zero is not allowed.")

End If

End If

End If

End Sub

Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Button17.Click

TextBox1.Text = "0"

End Sub

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

If TextBox1.Text < " " Then ' ⌫ DEL BUTTON

TextBox1.Text = Mid(TextBox1.Text, 1, Len(TextBox1.Text) - 1 + 1)

Else

TextBox1.Text = Mid(TextBox1.Text, 1, Len(TextBox1.Text) - 1)

End If

End Sub

End Class

You might also like