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

GUI Lab Programs 1 To 4

The document describes 4 programs written in VB to: 1. Create a simple arithmetic calculator using buttons and textbox controls 2. Generate a Fibonacci series and calculate the sum of N numbers using loops 3. Create a menu and draw shapes like circles, lines, rectangles in an MDI form 4. Create an input form to read data from textboxes and write to a file

Uploaded by

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

GUI Lab Programs 1 To 4

The document describes 4 programs written in VB to: 1. Create a simple arithmetic calculator using buttons and textbox controls 2. Generate a Fibonacci series and calculate the sum of N numbers using loops 3. Create a menu and draw shapes like circles, lines, rectangles in an MDI form 4. Create an input form to read data from textboxes and write to a file

Uploaded by

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

EX.

NO:1
SIMPLE ARITHMETIC CALCULATOR
DATE:

AIM

To write a VB Program to construct the Arithmetic Calculator (Simple).

ALGORITHM

STEP 1: Start -> Program -> Microsoft Visual Studio 6.0-> Visual Basic 6.0

STEP 2: Select File -> New -> Standard.exe

STEP 3: Design the form with required controls.

STEP 4: Create Control Array for command buttons

STEP 5: Type the coding

STEP 6: Build and execute the application

STEP 7: Stop the program


FORM DESIGN
PROGRAM CODING

Dim a, b, c, d
Dim s As String

Private Sub CLEAR_Click()


Text1.Text = ""
End Sub

Private Sub div_Click()


d = Text1.Text
Text1.Text = ""
s = "/"
End Sub

Private Sub dot_Click()


Text1.Text = Text1.Text + dot.Caption
End Sub

Private Sub Eight_Click()


Text1.Text = Text1.Text + Eight.Caption
End Sub

Private Sub equal_Click()


If (s = "+") Then
Text1.Text = Val(a) + Val(Text1.Text)
ElseIf (s = "-") Then
Text1.Text = Val(b) - Val(Text1.Text)
ElseIf (s = "*") Then
Text1.Text = Val(c) * Val(Text1.Text)
ElseIf (s = "/") Then
Text1.Text = Val(d) / Val(Text1.Text)
End If
End Sub
Private Sub five_Click()
Text1.Text = Text1.Text + five.Caption
End Sub

Private Sub four_Click()


Text1.Text = Text1.Text + four.Caption
End Sub

Private Sub minus_Click()


b = Text1.Text
Text1.Text = ""
s = "-"
End Sub

Private Sub multiplication_Click()


c = Text1.Text
Text1.Text = ""
s = "*"
End Sub

Private Sub nine_Click()


Text1.Text = Text1.Text + nine.Caption
End Sub

Private Sub OFF_Click()


Text1.Text = ""
zero.Enabled = False
one.Enabled = False
two.Enabled = False
three.Enabled = False
four.Enabled = False
five.Enabled = False
six.Enabled = False
Seven.Enabled = False
Eight.Enabled = False
nine.Enabled = False
dot.Enabled = False
plus.Enabled = False
minus.Enabled = False
multiplication.Enabled = False
div.Enabled = False
clear.Enabled = False
equal.Enabled = False
End Sub

Private Sub ON_Click()


zero.Enabled = True
one.Enabled = True
two.Enabled = True
three.Enabled = True
four.Enabled = True
five.Enabled = True
six.Enabled = True
Seven.Enabled = True
Eight.Enabled = True
nine.Enabled = True
plus.Enabled = True
minus.Enabled = True
multiplication.Enabled = True
div.Enabled = True
dot.Enabled = True
equal.Enabled = True
clear.Enabled = True
End Sub

Private Sub one_Click()


Text1.Text = Text1.Text + one.Caption
End Sub
Private Sub plus_Click()
a = Text1.Text
Text1.Text = ""
s = "+"
End Sub

Private Sub Seven_Click()


Text1.Text = Text1.Text + Seven.Caption
End Sub

Private Sub six_Click()


Text1.Text = Text1.Text + six.Caption
End Sub

Private Sub three_Click()


Text1.Text = Text1.Text + three.Caption
End Sub

Private Sub two_Click()


Text1.Text = Text1.Text + two.Caption
End Sub

Private Sub zero_Click()


Text1.Text = Text1.Text + zero.Caption
End Sub
OUTPUT
RESULT

Thus the above program has been run successfully.


EX.NO:2(A) LOOPS AND DECISION MAKING STATEMENTS - GENERATE
FIBONACCI SERIES
DATE:

AIM

To write a VB Program for generate Fibonacci Series.

ALGORITHM

Step - 1: Start the process.

Step - 2: Create a new Project.

Step - 3: Declare the variables a,b,c,series as integer type.

Step - 4: Draw the picture box for seeing the output.

Step - 5: Through the Inputbox enter the number of series for printing
Fibonacci series

Step - 6: Save and execute the project.

Step - 7 : Stop the process.


FORM DESIGN
PROGRAM CODING

Dim a, b, c, series As Integer

Private Sub Command1_Click()


Picture1.Cls
series = InputBox("Enter the number of series")
a=1
For x = 1 To series
If x > 2 Then
c=a+b
a=b
b=c
Picture1.Print c & Space(2);
Else
Picture1.Print a & Space(2);
End If
Next x
End Sub
OUTPUT
RESULT

Thus the above program has been run successfully.


EX.NO:2(B)
LOOPS AND DECISION MAKING STATEMENTS - FIND THE SUM
OF N NUMBERS
DATE:

AIM

To write a VB Program to find the sum of N numbers.

ALGORITHM

Step - 1: Start the process.

Step - 2: Create a new Project.

Step - 3: Declare the variables a,n and sum as integer type.

Step - 4: Keep the command button for getting the limit and finding the sum

Step - 5: Give the input for printing the sum of n numbers, based on the for loop
the input will be given in the text box until the condition is true.

Step - 6: Save and execute the project.

Step - 7 : Stop the process.


FORM DESIGN
PROGRAM CODING

Dim a, n, sum As Integer

Private Sub Command1_Click()


n = InputBox("Enter the limit")
End Sub

Private Sub Command2_Click()


sum = 0
For k = 1 To n
sum = sum + k
Next k
MsgBox "the result is" & sum
End Sub
OUTPUT
RESULT

Thus the above program has been run successfully.


EX.NO:2(C)
LOOPS AND DECISION MAKING STATEMENTS - TO DISPLAY
THE NUMBERS/SYMBOLS IN TRIANGLE FORMAT
DATE:

AIM
To write a VB Program to display the numbers/symbols in trianlge
format.

ALGORITHM

Step - 1: Start the process.

Step - 2: Create a new Project.

Step - 3: Declare the variables n,i,j as integer type.

Step - 4: keep the command button for printing the value in a triangle format.

Step - 5: Through the Inputbox enter the number of series for printing in a
triangle format according the i and j values in the for loop

Step - 6: Save and execute the project.

Step - 7 : Stop the process.


FORM DESIGN
CODING

Dim n,i,j as integer

Private Sub Command1_Click()


n = Val(InputBox("Enter number of rows"))
For i = n To 1 Step -1
For j = n To i Step -1
Print " * ";
Next j
Print ""
Next i

Print ""
Print ""
Print ""

For i = 1 To n
For j = i To n
Print " * ";
Next j
Print ""
Next i
End Sub
OUTPUT
RESULT

Thus the above program has been run successfully.


EX.NO: 3
CREATE A MENU AND MDI FORMS
DATE:

AIM

To write a VB Program for creating MENU and MDI forms.

ALGORITHM

STEP 1: Start -> Program -> Microsoft Visual Studio 6.0-> Visual Basic 6.0

STEP 2: Select File -> New -> Standard.exe

STEP 3: Design the form with required controls.

STEP 4: Create a menu using Menu Editor

STEP 5: Type the coding

STEP 6: Build and execute the application

STEP 7: Stop the program


FORM DESIGN
PROGRAM CODING

Private Sub mnuCircle_Click()


Picture1.Cls
Picture1.DrawWidth = 3
Picture1.Circle (1800, 1800), 1000, vbBlue
End Sub

Private Sub mnuLine_Click()


Picture1.Cls
Picture1.DrawWidth = 3
Picture1.Line (2000, 2000)-(3500, 3500), vbRed
End Sub

Private Sub mnuRectanlge_Click()


Picture1.Cls
Picture1.DrawWidth = 3
Picture1.Line (300, 300)-Step(4000, 2000), vbGreen, B
End Sub

Private Sub mnuSquare_Click()


Picture1.Cls
Picture1.DrawWidth = 3
Picture1.Line (1300, 1300)-Step(1300, 1300), vbPink, B
End Sub
OUTPUT

Printing Line

Printing Square
Printing Circle

RESULT

Thus the above program has been run successfully.


EX.NO: 4 CREATE A SIMPLE INPUT SCREEN WITH FOUR BASIC
CONTROLS TO READ INPUT AND WRITE IT TO A FILE
DATE:

AIM

To write a VB Program for create a simple input screen with four basic
controls to read input and write it to a file.

ALGORITHM

STEP 1: Start -> Program -> Microsoft Visual Studio 6.0-> Visual Basic 6.0

STEP 2: Select File -> New -> Standard.exe

STEP 3: Design the form with required controls

STEP 4: Create a text file “Sample.txt”using Notepad

STEP 5: Type the coding

STEP 6: Build and execute the application

STEP 7: Stop the program


FORM DESIGN
PROGRAM CODING

Dim filepath As String


Dim record As String

Private Sub Command1_Click()


filepath = "C:\VB\myfile.txt"
filenum = FreeFile
record = record + Text1.Text + " "
record = record + Text2.Text + " "

If Option1.Value = True Then


record = record + "Male "
Else
record = record + "Female "
End If
record = record + Text3.Text
Open filepath For Append As #1
Print #1, record
Close #1

MsgBox "Record inserted into text file", vbDefaultButton1, "Submit"


record = ""
Text1.Text = ""
Text2.Text = ""
Option1.Value = True
Option2.Value = False
Text3.Text = ""
End Sub
OUTPUT
RESULT

Thus the above program has been run successfully.

You might also like