Sunteți pe pagina 1din 10

OLYMPIA COLLEGE

SCHOOL OF COMPUTING

DIPLOMA IN INFORMATION
TECHNOLOGY

INDIVIDUAL ASSIGNMENT

VISUAL
PROGRAMMING

NAME AS PER IC / PASSPORT:
COLLEGE INDEX NO:
IC NO / PASSPORT NO:
BATCH NO:

CAMPUS: PETALING JAYA

WORDS COUNT: 1002

Table oI content
Table oI content

NO Content Page

1.Acknowledgement........................... i

2.Table oI content............................... ii

3.Question 1........................................ 1

4.Answer 1......................................... 2 - 3

5.Question 2....................................... 4

6.Answer 2......................................... 5-7

7.ReIerence......................................... 8






Diploma in InIormation Technology ii
Olympia College Petaling Jaya Campus
Question 1





Question 1

Write a program that allows the user to change
the shape by selecting a particular shape Irom
a list oI options Irom a list box, as well as
changing its color through a common dialog
box.









Diploma in InIormation Technology 1
Olympia College Petaling Jaya Campus
Question 1 (Answer 1)



Public Class Form1

Private Sub Button1Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
ColorDialog1.ShowDialog()
PictureBox1.BackColor ColorDialog1.Color
PictureBox2.BackColor ColorDialog1.Color
PictureBox3.BackColor ColorDialog1.Color
PictureBox4.BackColor ColorDialog1.Color
PictureBox5.BackColor ColorDialog1.Color
PictureBox6.BackColor ColorDialog1.Color

End Sub

Private Sub ListBox1SelectedIndexChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles ListBox1.SelectedIndexChanged
II ListBox1.SelectedItem "Rectangle" Then
PictureBox1.Show()
PictureBox2.Hide()
PictureBox3.Hide()
PictureBox4.Hide()
PictureBox5.Hide()
PictureBox6.Hide()






Diploma in InIormation Technology 2
Olympia College Petaling Jaya Campus
Question 1 (Answer 1

ElseII ListBox1.SelectedItem "Square" Then
PictureBox2.Show()
PictureBox1.Hide()
PictureBox3.Hide()
PictureBox4.Hide()
PictureBox5.Hide()
PictureBox6.Hide()
ElseII ListBox1.SelectedItem "Circle" Then
PictureBox3.Show()
PictureBox1.Hide()
PictureBox6.Hide()
PictureBox4.Hide()
PictureBox5.Hide()
PictureBox2.Hide()
ElseII ListBox1.SelectedItem "Oval" Then
PictureBox4.Show()
PictureBox1.Hide()
PictureBox3.Hide()
PictureBox6.Hide()
PictureBox5.Hide()
PictureBox2.Hide()
ElseII ListBox1.SelectedItem "Rounded Rectangle" Then
PictureBox5.Show()
PictureBox1.Hide()
PictureBox3.Hide()
PictureBox4.Hide()
PictureBox6.Hide()
PictureBox2.Hide()
ElseII ListBox1.SelectedItem "Rounded Square" Then
PictureBox6.Show()
PictureBox1.Hide()
PictureBox3.Hide()
PictureBox4.Hide()
PictureBox5.Hide()
PictureBox2.Hide()
End II

End Sub
End Class







Diploma in InIormation Technology 3
Olympia College Petaling Jaya Campus
Question 2






Question 2

Create a simple calculator using Visual Basic.
The calculator is used by clicking on the
appropriate buttons just as you would a real
calculator.









Diploma in InIormation Technology 4
Olympia College Petaling Jaya Campus
Question 2 (Answer 2)


Public Class Form1
Dim num1 As Double
Dim num2 As Double
Dim hole As String
Dim total As Double



Private Sub Button16Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button16.Click
TextBox1.Text TextBox1.Text & "0"
End Sub

Private Sub Button7Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button7.Click
TextBox1.Text TextBox1.Text & "1"
End Sub

Private Sub Button8Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button8.Click
TextBox1.Text TextBox1.Text & "2"
End Sub

Private Sub Button9Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button9.Click
TextBox1.Text TextBox1.Text & "3"
End Sub



Diploma in InIormation Technology 5
Olympia College Petaling Jaya Campus
Question 2 (Answer 2)

Private Sub Button4Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
TextBox1.Text TextBox1.Text & "4"
End Sub

Private Sub Button5Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
TextBox1.Text TextBox1.Text & "5"
End Sub

Private Sub Button6Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button6.Click
TextBox1.Text TextBox1.Text & "6"
End Sub

Private Sub Button1Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Text TextBox1.Text & "7"
End Sub

Private Sub Button2Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
TextBox1.Text TextBox1.Text & "8"
End Sub

Private Sub Button3Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
TextBox1.Text TextBox1.Text & "9"
End Sub

Private Sub Button14Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button14.Click
TextBox1.Text TextBox1.Text & "."
End Sub

Private Sub Button10Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button10.Click
num1 Val(TextBox1.Text)
TextBox1.Text ""
hole ""
End Sub

Private Sub Button11Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button11.Click
num1 Val(TextBox1.Text)
TextBox1.Text ""
hole "-"
End Sub


Diploma in InIormation Technology 6
Olympia College Petaling Jaya Campus
Question 2 (Answer 2)

Private Sub Button12Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button12.Click
num1 Val(TextBox1.Text)
TextBox1.Text ""
hole "*"
End Sub

Private Sub Button13Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button13.Click
num1 Val(TextBox1.Text)
TextBox1.Text ""
hole "/"
End Sub

Private Sub Button15Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button15.Click
num2 Val(TextBox1.Text)

II hole "" Then
total Val(num1) Val(num2)
ElseII hole "-" Then
total Val(num1) - Val(num2)
ElseII hole "*" Then
total Val(num1) * Val(num2)
ElseII hole "/" Then
total Val(num1) / Val(num2)
End II

TextBox1.Text Val(total)
End Sub

Private Sub Button17Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button17.Click
TextBox1.Text ""
End Sub
End Class







Diploma in InIormation Technology 7
Olympia College Petaling Jaya Campus
ReIerence

ReIerence

Internet

O http://www.homeandlearn.co.uk/net/nets1p19.html
O http://www.vbtutor.net/vb6/lesson18.html




Book
O SAMS


Human Resource
O Ms. Leela, Olympia College Petaling Jaya Campus, Visual Programming lecturer,
May - August 2011.









Diploma in InIormation Technology 8
Olympia College Petaling Jaya Campus

S-ar putea să vă placă și