Practical 10:
Write a program in Visual Basic to find the sum of first 100 numbers entered using
Do loop.
Solution:
Dim i, s As Integer
Private Sub add_Click()
i=0
s=0
Do While i <= 100
s=s+i
i=i+1
Loop
Text1.Text = s
End Sub
Private Sub clear_Click()
Text1.Text = ""
End Sub
Private Sub exit_Click()
End
End Sub
OUTPUT 10:
Practical 11:
Write a program in Visual Basic that calculates area and selection of two shapes,
Circle and Rectangle.
Solution:
Private Sub areaofCircle_Click()
Text1.Text = 3.14 * Val(Text2.Text) * Val(Text2.Text)
End Sub
Private Sub areaofRect_Click()
Text1.Text = Val(Text3.Text) * Val(Text4.Text)
End Sub
Private Sub Circle_Click()
Shape1.Visible = True
Label1.Visible = True
areaofCircle.Visible = True
Clear.Visible = True
Shape2.Visible = False
Label2.Visible = False
areaofRect.Visible = False
Text1.Visible = True
Text2.Visible = True
Text3.Visible = False
Text4.Visible = False
End Sub
Private Sub Clear_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub
Private Sub Exit_Click()
End
End Sub
Private Sub Rectangle_Click()
Shape1.Visible = False
Label1.Visible = False
areaofCircle.Visible = False
Clear.Visible = True
Shape2.Visible = True
Label2.Visible = True
areaofRect.Visible = True
Text1.Visible = True
Text2.Visible = False
Text3.Visible = True
Text4.Visible = True
End Sub
OUTPUT 11:
Practical 12:
Create a graphic editor using Visual Basic, which has the following functions :
change color, change line width, fill color, change border color etc. (Select any
three properties to change).
Solution:
Private Sub big_Click()
Shape1.Height = 2500
Shape1.Width = 2500
End Sub
Private Sub blue_Click()
Shape1.FillColor = vbBlue
Shape1.FillStyle = 0
End Sub
Private Sub green_Click()
Shape1.FillColor = vbGreen
Shape1.FillStyle = 0
End Sub
Private Sub medium_Click()
Shape1.Height = 2000
Shape1.Width = 2000
End Sub
Private Sub red_Click()
Shape1.FillColor = vbRed
Shape1.FillStyle = 6
End Sub
Private Sub small_Click()
Shape1.Height = 1500
Shape1.Width = 1500
End Sub
Private Sub thick_Click()
Shape1.BorderWidth = 5
Shape1.BorderColor = vbBlack
End Sub
Private Sub thicker_Click()
Shape1.BorderWidth = 10
Shape1.BorderColor = vbYellow
End Sub
Private Sub thin_Click()
Shape1.BorderWidth = 1
Shape1.BorderColor = vbBlack
End Sub
OUPUT 12:
Practical 13:
Write a program in Visual Basic that will display a picture with red color as
background on form-load event. When the drag-drop operation is carried out, the
background color must change to green and when the drag-over operation is
carried out, the background color must change to blue.
Solution:
Private Sub Form_Load()
Picture1.BackColor = vbRed
End Sub
Private Sub object_DragDrop(Source As Control, X As Single, Y As Single)
Picture1.BackColor = vbBlue
End Sub
Private Sub object_DragOver(Source As Control, X As Single, Y As Single, State As
Integer)
Picture1.BackColor = vbGreen
End Sub
Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)
Picture1.BackColor = vbBlue
End Sub
Private Sub Picture1_DragOver(Source As Control, X As Single, Y As Single, State
As Integer)
Picture1.BackColor = vbGreen
End Sub
OUTPUT 13:
Practical 14:
Write a program in Visual Basic that creates a simple form, which asks user to
enter marks obtained in 6 subjects. At the end it should display the average and
calculate the result using CASE condition.
Solution:
Private Sub clear_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
End Sub
Private Sub exit_Click()
End
End Sub
Private Sub result_Click()
Dim t1 As Boolean
t1 = True
s1 = Val(Text1.Text)
s2 = Val(Text2.Text)
s3 = Val(Text3.Text)
s4 = Val(Text4.Text)
s5 = Val(Text5.Text)
s6 = Val(Text6.Text)
Avg = (s1 + s2 + s3 + s4 + s5 + s6) / 6
Select Case t1
Case s1 < 40 Or s2 < 40 Or s3 < 40 Or s4 < 40 Or s5 < 40 Or s6 < 40
Text7.Text = "Failed"
Case Avg < 60
Text7.Text = "Second Class"
Case Else
Text7.Text = "First Class"
End Select
End Sub
OUTPUT 14:
Practical 15:
Write a program in Visual Basic to prepare a list of items in one list (say computer
& peripherals). After selecting the items, the selection must be listed in second list
which will enable users to add the items from the first or second list if needed, as
well as option to remove items from the list.
Solution:
Private Sub addl1_Click()
Dim str1 As String
str1 = InputBox(" Please Enter name of new item")
List1.AddItem str1
End Sub
Private Sub addl2_Click()
Dim str2 As String
str2 = InputBox(" Please Enter name of new item")
List2.AddItem str2
End Sub
Private Sub backw_Click()
List1.AddItem List2.Text
End Sub
Private Sub forward_Click()
List2.AddItem List1.Text
End Sub
Private Sub reml1_Click()
If List1.ListIndex > -1 Then
List1.RemoveItem List1.ListIndex
End If
End Sub
Private Sub reml2_Click()
If List2.ListIndex > -1 Then
List2.RemoveItem List2.ListIndex
End If
End Sub
Private Sub end_Click()
End
End Sub
OUTPUT 15: