0% found this document useful (0 votes)
556 views53 pages

To Write A Program in VB To Create A Calculator

The document describes how to write a program in Visual Basic (VB) to create a calculator application. It includes code snippets to add, subtract, multiply, and divide numbers. It also covers taking the modulus, square root, and comparing numbers. Additionally, it shows how to create login/registration forms, count and arrange numbers in loops, and determine if a number is even, odd, or a leap year. The overall purpose is to demonstrate the creation of a full-featured calculator program using VB code.

Uploaded by

1990 rahul
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
556 views53 pages

To Write A Program in VB To Create A Calculator

The document describes how to write a program in Visual Basic (VB) to create a calculator application. It includes code snippets to add, subtract, multiply, and divide numbers. It also covers taking the modulus, square root, and comparing numbers. Additionally, it shows how to create login/registration forms, count and arrange numbers in loops, and determine if a number is even, odd, or a leap year. The overall purpose is to demonstrate the creation of a full-featured calculator program using VB code.

Uploaded by

1990 rahul
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 53

To write a program in VB to create a calculator

To write a program in VB to add the two numbers

Private Sub Command1_Click()

Dim A As Integer

Dim B As Integer

Dim R As Integer

A = Val(Text1.Text)

B = Val(Text2.Text)

Text3.Text = A + B

End Sub
To write a program in VB to subtract two numbers

Private Sub Command2_Click()

Dim A As Integer

Dim B As Integer

Dim R As Integer

A = Val(Text1.Text)

B = Val(Text2.Text)

Text3.Text = A - B

End Sub
To write a program in VB to multiply two numbers

Private Sub Command3_Click()

Dim A As Integer

Dim B As Integer

Dim R As Integer

A = Val(Text1.Text)

B = Val(Text2.Text)

Text3.Text = A * B

End Sub
To write a program in VB to divide to numbers

Private Sub Command4_Click()

Dim A As Integer

Dim B As Integer

Dim R As Integer

A = Val(Text1.Text)

B = Val(Text2.Text)

Text3.Text = A / B

End Sub
To write a program in VB to take mod of two numbers

Private Sub Command5_Click()

Dim A As Integer

Dim B As Integer

Dim R As Integer

A = Val(Text1.Text)

B = Val(Text2.Text)

Text3.Text = A Mod B

End Sub
To write a program in VB to take square root of two
numbers
Private Sub Command6_Click()

Dim A As Integer

Dim B As Integer

Dim R As Integer

A = Val(Text1.Text)

Text3.Text = Sqr(A)

End Sub
To write a program in VB to clear the screen

Private Sub Command7_Click()

Text1.Text = ""

Text2.Text = ""

Text3.Text = ""

End Sub

To write a program in VB to exit the screen

Private Sub Command8_Click()

End

End Sub
To write a program in VB to make comparison between two
numbers.
COMPARISON BETWEEN TWO NUMBERS

Private Sub Command1_Click()


Dim A As Integer

Dim B As Integer

A = Val(Text1.Text)

B = Val(Text2.Text)

If (A >= B) Then

textmsg = MsgBox("FIRST NUMBER IS GREATER")

Else

textmsg = MsgBox("SECOND NUMBER IS GREATER")

End If

End Sub
Private Sub Command2_Click()

Dim A As Integer

Dim B As Integer

A = Val(Text1.Text)

B = Val(Text2.Text)

If (A <= B) Then

textmsg = MsgBox("FIRST NUMBER IS SMALLER")

Else

textmsg = MsgBox("SECOND NUMBER IS SMALLER")

End If

End Sub
Private Sub Command5_Click()

Dim A As Integer

Dim B As Integer

If (A = B) Then

TEXTMSG = MsgBox("BOTH NUMBERS ARE EQUAL")

Else

TEXTMSG = MsgBox("BOTH NUMBERS ARE NOT EQUAL")

End If

End Sub
TO CLEAR THE SCREEN AND TO EXIT

Private Sub Command3_Click()

Text1.Text = ""

Text2.Text = ""

End Sub

TO EXIT

Private Sub Command4_Click()

End

End Sub

COMPARISON BETWEEN THREE NUMBERS


COMPARISON BETWEEN THREE NUMBERS
Private Sub Command1_Click()

Dim A As Integer

Dim B As Integer

Dim C As Integer

A = Val(Text1.Text)

B = Val(Text2.Text)

C = Val(Text3.Text)

If (A >= B) And (A >= C) Then

TEXTMSG = MsgBox("FIRST NUMBER IS GREATER")

ElseIf (B >= C) And (B >= A) Then

TEXTMSG = MsgBox("SECOND NUMBER IS GREATER")

Else

TEXTMSG = MsgBox("THIRD NUMBER IS GREATER")

End If

End Sub

Private Sub Command2_Click()

Dim A As Integer
Dim B As Integer

Dim C As Integer

A = Val(Text1.Text)

B = Val(Text2.Text)

C = Val(Text3.Text)

If (A <= B) And (A <= C) Then

TEXTMSG = MsgBox("FIRST NUMBER IS SMALLER")

ElseIf (B <= C) And (B <= A) Then

TEXTMSG = MsgBox("SECOND NUMBER IS SMALLER")

Else

TEXTMSG = MsgBox("THIRD NUMBER IS SMALLER")

End If

End Sub
TO CLEAR

Private Sub Command3_Click()

Text1.Text = ""

Text2.Text = ""

Text3.Text = ""

End Sub

TO EXIT

Private Sub Command4_Click()

End

End Sub
TO CREATE A LOGIN BOX
TO CREATE A REGISTRATION FORM
COUNTING
Private Sub Command1_Click()

For i = 1 To 10 Step 1

Print i

Next i

End Sub
TO EXIT

Private Sub Command2_Click()

End

End Sub
TO ADD TABLE OF TWO
Private Sub Command1_Click()

For i = 2 To 20 Step 2

Print i

Next i

End Sub
TO EXIT

Private Sub Command2_Click()

End

End Sub
Private Sub Command1_Click()

Dim N As Integer

N = Val(Text1.Text)

For i = 1 To N Step 1

Print i

Next i

End Sub
Private Sub Command2_Click()

Text1.Text = ""

End Sub

Private Sub Command3_Click()

End

End Sub
Private Sub Command1_Click()

Dim N As Integer

N = Val(Text1.Text)

For i = N To N * 10 Step N

Print i

Next i

End Sub
TO CLEAR AND TO EXIT

Private Sub Command2_Click()

Text1.Text = ""

End Sub

Private Sub Command3_Click()

End

End Sub
TO ORDER THE ALPHABETS
ARRANGE ALPHABETS IN SERIAL ORDER

Private Sub Command1_Click()

For i = 65 To 69 Step 1

For j = 65 To i Step 1

Print Chr(i);

Next j

Print

Next i

END SUB
TO ARRANGE ALPHABETS IN REVERSE ORDER

Private Sub Command2_Click()

For i = 69 To 65 Step -1

For j = 65 To i Step 1

Print Chr(i);

Next j

Print

Next i

End Sub
TO EXIT

Private Sub Command3_Click()

End

End SuB
Private Sub Command1_Click()

For i = 65 To 69 Step 1

For J = 65 To i Step 1

Print Chr(J);

Next J

Print

Next i

End Sub
Private Sub Command2_Click()

For i = 69 To 65 Step -1

For J = 65 To i Step 1

Print Chr(J);

Next J

Print

Next i

End Sub
Private Sub Command3_Click()

End

End Sub
Private Sub Command1_Click()

For i = 1 To 5 Step 1

For J = 1 To i Step 1

Print "*";

Next J

Print

Next i

End Sub
Private Sub Command2_Click()

For i = 5 To 1 Step -1

For J = 1 To i Step 1

Print "*";

Next J

Print

Next i

End Sub
TO EXIT

Private Sub Command3_Click()

End

End Sub
SELECT EVEN OR ODD NUMBERS
Private Sub Command1_Click()

Dim N As Integer

N = Val(Text1.Text)

If (N Mod 2 = 0) Then

MsgBox "NUMBER IS EVEN"

Else

MsgBox "NUMBER IS ODD"

End If

End Sub
TO CLEAR

Private Sub Command2_Click()

Text1.Text = ""

End Sub

TO END

Private Sub Command3_Click()

End

End Sub
Private Sub Command1_Click()

Dim N As Integer

N = Val(Text1.Text)

If (N Mod 400 = 0) Then

MsgBox "YEAR IS LEAP YEAR"

ElseIf (N Mod 100 = 0) Then

MsgBox "YEAR IS NOT LEAP YEAR"

ElseIf (N Mod 4 = 0) Then

MsgBox "YEAR IS LEAP YEAR"

Else

MsgBox "YEAR IS NOT LEAP YEAR"

End If

End Sub
TO CLEAR

Private Sub Command2_Click()

Text1.Text = ""

End Sub

TO EXIT

Private Sub Command3_Click()

End

End Sub

You might also like