VB.NET2
-
Upload
ravi-ranjan -
Category
Documents
-
view
14 -
download
0
Transcript of VB.NET2
Introduction to Visual Basic .NET
APIIT SD INDIA Page 1
INTRODUCTION TO Visual Basic .net (CE00328-1)
ASSESSMENT MODE: INDIVIDUAL
TASKS 4 , 5 , 6
HAND OUT DATE: 6 –February-2012
HAND IN DATE: 27-Aprail-2012
SUBMITTED BY SUBMITTED TO
Raju Ranjan MS.SAKSHI POPLI
(Pt1082221) (MODULE LECTURER)
Introduction to Visual Basic .NET
APIIT SD INDIA Page 2
CERTIFICATE
This is to certify that Mr. Raju Ranjan of 4th Semester student (Computing Branch) of APIIT
SD INDIA have successfully completed his individual assignment named of V B .net on
Tasks 4 , 4 , 6 under the sheer guidance of Ms. Sakshi Popli.
Submitted by: - Submitted to:-
Raju Ranjan Ms.Sakshi Popli
PT1082221 Module lecturer
Introduction to Visual Basic .NET
APIIT SD INDIA Page 3
TABLE OF CONTEXT
Acknowledgement……………………………………………………………………………..4
Task 4………………………………………………………………………………………….5
Introduction
Objective
Planning
Design………………………………………………………………………………………….6
Implementation………………………………………………………………………………...7
Testing………………………………………………………………………………………....8
Task …………………………………………………………………………………………12
Introduction
Objective
Planning
Design………………………………………………………………………………………..13
Implementation……………………………………………………………………………….14
Testing………………………………………………………………………………………..16
Task …………………………………………………………………………………………17
Introduction
Objective
Planning………………………………………………………………………………………18
Design………………………………………………………………………………………..19
Implementation……………………………………………………………………………….20
Testing………………………………………………………………………………………..22
Conclusion……………………………………………………………………………………23
References……………………………………………………………………………………24
Introduction to Visual Basic .NET
APIIT SD INDIA Page 4
ACKNOWLEDGEMENT
This project is provided to make .net application. I give my full regards for providing the
opportunity to make “Visual Basic .net”, Ms.Sakshi Popli who had continually helped and
motivated us to complete the assignment. It was really a wonderful experience for me to work
under such a dynamic and helping personality. She gave us the knowledge of each &
everything related and beyond the module in order to enhance our skills and this assignment
has been made possible due to her expertise and knowledge.
Last and but not the least, I want to acknowledge all my friends and colleagues who
supported me in my assignment.
Submitted By:
Raju Ranjan
(Pt1082221)
Introduction to Visual Basic .NET
APIIT SD INDIA Page 5
Task4 – Identify Flags
Introduction:- A new project called Identify Flags , in this project we should display
the flag of a randomly selected country and provide the user with a list of countries
from which must choose the correct one. Through creating this task I learned many
things firstly how to enabled or disabled the buttons , label and panel, how to generate
random numbers, how to use select statement to determine which country has been
selected, use of if statement to check whether answer is correct and use of methods and
parameters to avoid code repetition.
Task 4:- Identify Flags
Objective:-
use radio buttons to provide choices
use panels to group options
generate random numbers
use select statement to determine which country has been selected
display image in picture box
use if statement to check whether answer is correct
use methods and parameters to avoid code repetition
Planning:-
Firstly I plan to create a form and specify the name and then declare all the variables.
I plan to take the same and small size of flag so that it looks better in picture box.
Then I think to generate random number and used to select the name of a country
which is then stored in a variable.
Then I plan how to use select statement to determine which country has been selected.
Then I plan to use if statement to check whether answer is correct.
Then I enabled all available country options so that the user can select the one they
think is correct, and the Flag button is disabled.
I plan to display Correct’ message when correct country selected.
And also plan to show Incorrect’ message when wrong country selected.
I plan to use Single method to avoid repetition of code.
Introduction to Visual Basic .NET
APIIT SD INDIA Page 6
Design:-
Flag Button
Picture Box
Lable
Radio
Button
Introduction to Visual Basic .NET
APIIT SD INDIA Page 7
`
Object Property Value
Form1 Name
Text
Frmflag
Identify Flags
Label1 Name
Text
lblMessage
“ “
RadioButton1 Name
Text
btnBelgium
Belgium
RaioButton2 Name
Text
btnCanada
Canada
RadioButton3 Name
Text
btnChina
China
RadiButton4 Name
Text
btnFinland
Finland
RadioButton5 Name
Text
btnFrance
France
RadioButton6 Name
Text
btnSudan
Sudan
RadioButton7 Name
Text
btnZambia
Zambia
Button Name
Text
btnFlag
Flag
Implementation:-
#Region "Identify flags"
Public Class Form1
Dim country As String 'declear country as string variable
Dim randomnum As Integer 'declear randomnum as integer
Dim randum As New Random 'declear randum as Randum
#Region "disabler function"
Public Sub disabler() 'declear a function for disabeling the
radiobutton
rdbCanada.Enabled = True 'make radio button disabled
rdbBelgium.Enabled = True 'make radio button disabled
rdbChina.Enabled = True 'make radio button disabled
rdbFinland.Enabled = True 'make radio button disabled
rdbSudan.Enabled = True 'make radio button disabled
rdbZambia.Enabled = True 'make radio button disabled
rdbFrance.Enabled = True 'make radio button disabled
End Sub
#End Region
#Region "form load"
Introduction to Visual Basic .NET
APIIT SD INDIA Page 8
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.Text = "Identify flags" 'caption of form
btnFlag.Text = "Flag" 'label of flag button
rdbBelgium.Text = "Belgium" 'label of belgium button
rdbCanada.Text = "Canada" 'label of canada button
rdbChina.Text = "China" 'label of china button
rdbFinland.Text = "Finland" 'label of finland button
rdbFrance.Text = "France" 'label of france button
rdbSudan.Text = "Sudan" 'label of sudan button
rdbZambia.Text = "Zambia" 'label of zambia button
End Sub
#End Region
#Region "Flag button"
Private Sub btnFlag_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnFlag.Click
btnFlag.Enabled = False 'flag button is enabled
randomnum = randum.Next(1, 7) 'a randum number is generated
pnlconty.Enabled = True 'panel is enabled at click event of
flag button
lblMessage.Enabled = False 'label is disabled after click event
of flag button
lblMessage.Text = "
" 'label for showing the answer
Select Case randomnum 'use select statement to determine
which country is selected
Case 1
picFlag.Image = Image.FromFile("belgium-flag-1.png")
country = "Belgium"
'country variable store the value of Belgium
Case 2
picFlag.Image = Image.FromFile("Canada-Flag.png")
country = "Canada"
'country variable store the value of
Case 3
picFlag.Image = Image.FromFile("China-Flag-icon-
250x250.png")
country = "China"
'country variable store the value of China
Case 4
picFlag.Image = Image.FromFile("finland-flag-1.png")
country = "Finland"
'country variable store the value of Finland
Case 5
picFlag.Image = Image.FromFile("france.png")
country = "France"
'country variable store the value of France
Case 6
picFlag.Image = Image.FromFile("Sudan.png")
country = "Sudan"
'country variable store the value of Sudan
Case 7
picFlag.Image = Image.FromFile("Zambia.png")
country = "Zambia"
'country variable store the value of Zambia
pnlconty.Enabled = True
End Select
Introduction to Visual Basic .NET
APIIT SD INDIA Page 9
End Sub
#End Region
#Region "RadioButtonBelgium"
Private Sub rdbBelgium_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles rdbBelgium.CheckedChanged
If country = "Belgium" Then 'if statement
for choosing the correct answer
lblMessage.Text = " Answer is correct"
Else
lblMessage.Text = " Answer is incorrect"
End If
pnlconty.Enabled = False 'panel is disabled after the click
event of radio button
rdbBelgium.Checked = False 'it unchecked the radio button
btnFlag.Enabled = True 'flag button is enabled after click
event of radio button
End Sub
#End Region
#Region "RadioButton Canada"
Private Sub rdbCanada_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles rdbCanada.CheckedChanged
If country = "Canada" Then
lblMessage.Text = " Answer is correct"
Else
lblMessage.Text = " Answer is incorrect"
End If
pnlconty.Enabled = False 'panel is disabled after the click
event of radio button
btnFlag.Enabled = True 'flag button is enabled after click
event of radio button
rdbCanada.Checked = False 'it unchecked the radio button
End Sub
#End Region
#Region "RadioButton China"
Private Sub rdbChina_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles rdbChina.CheckedChanged
If country = "China" Then
lblMessage.Text = " Answer is correct"
Else
lblMessage.Text = " Answer is incorrect"
End If
pnlconty.Enabled = False 'panel is disabled after the click
event of radio button
btnFlag.Enabled = True 'flag button is enabled after click
event of radio button
rdbChina.Checked = False 'it unchecked the radio button
End Sub
#End Region
#Region "RadioButton Finland"
Private Sub rdbFinland_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles rdbFinland.CheckedChanged
If country = "Finland" Then
lblMessage.Text = " Answer is correct"
Else
lblMessage.Text = " Answer is incorrect"
End If
Introduction to Visual Basic .NET
APIIT SD INDIA Page 10
pnlconty.Enabled = False 'panel is disabled after the click
event of radio button
rdbFinland.Checked = False 'it unchecked the radio button
btnFlag.Enabled = True 'flag button is enabled after click
event of radio button
End Sub
#End Region
#Region "RadioButton France"
Private Sub rdbFrance_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles rdbFrance.CheckedChanged
If country = "France" Then
lblMessage.Text = " Answer is correct"
Else
lblMessage.Text = " Answer is incorrect"
End If
pnlconty.Enabled = False 'panel is disabled after the click
event of radio button
rdbFrance.Checked = False 'it unchecked the radio button
btnFlag.Enabled = True 'flag button is enabled after click
event of radio button
End Sub
#End Region
#Region "RadioBitton"
Private Sub rdbSudan_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles rdbSudan.CheckedChanged
If country = "Sudan" Then
lblMessage.Text = " Answer is correct"
Else
lblMessage.Text = " Answer is incorrect"
End If
pnlconty.Enabled = False 'panel is disabled after the click
event of radio button
rdbSudan.Checked = False 'it unchecked the radio button
btnFlag.Enabled = True 'flag button is enabled after click
event of radio button
End Sub
#End Region
#Region "RadioButton Zambia"
Private Sub rdbZambia_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles rdbZambia.CheckedChanged
If country = "Zambia" Then
lblMessage.Text = " Answer is correct"
Else
lblMessage.Text = " Answer is incorrect"
End If
pnlconty.Enabled = False 'panel is disabled after the click
event of radio button
rdbZambia.Checked = False 'it unchecked the radio button
btnFlag.Enabled = True 'flag button is enabled after click
event of radio button
End Sub
#End Region
End Class
#End Region
Introduction to Visual Basic .NET
APIIT SD INDIA Page 11
Testing:-
Project Title Identify Flag Testing Date 24/3/12
Test Case Name Identify Flag
Test Case ID 1
Conducted By Raju Ranjan
Description Display the flag of a randomly selected country
Testing Type Unit testing
Duration 2 day
Introduction to Visual Basic .NET
APIIT SD INDIA Page 12
Task 5 – Class Car
Introduction: - In this task I have to create a new Car object by specifying its location,
width, height, distance and colour. This Car class requires an enumerated type to determine
the direction of the car, either left or right. This will be used for drawing the car and moving
it. It must be drawn using the drawing methods provided in the Graphics class and should
look different depending which way it is facing. Through this project I learned to create a
class diagram also learn to create design through graphics. How we declare a constructor to
create Enum. Also we learned to move the car in picture Box.
Task 5:- Car Class
Objective:-
identify attributes
identify properties
identify methods
draw class diagram
implement enumerated types
implement private data
implement properties
implement constructor method
implement additional methods
Planning:-
Firstly I plan to create a form and specify the form name and then declare all the
variables.
Then I plan to create car through coordinate by the help of graphics.
I plan to specify its location, width, height, distance and its colour.
Also plan to provide Enum to fix the value of variable.
Plan to set the direction to left and move the car using the moveCar method
Plan to set the direction to right and move the car using the moveCar method
The left and right buttons must be disabled until the car has been created.
Introduction to Visual Basic .NET
APIIT SD INDIA Page 13
Design:-
Task Bar
Create Left Right
picRoad
btnCreate btnLeft btnRight
Introduction to Visual Basic .NET
APIIT SD INDIA Page 14
Object Property Value
Form1 Name
Text
frmcar
Test car
Button1 Name
Text
btnCreate
Create
Button2 Name
Text
btnLeft
Left
Button3 Name
Text
btnRight
Right
PictureBox1 Name
Text
picRoad
Implementation:-
Imports Test_Car.CarClass 'import the Test_CarClass
#Region "Class car"
Public Class Car 'declear a graphics
variable
Dim k As Graphics
Public draw As carmove 'declear a public type
variable
Dim car1 As New CarClass 'create a object car1 of
carclass
Dim x As Integer 'declear a variable
Dim y As Integer 'declear a variable
Dim a As Integer 'declear a variable
#Region "Enum"
Public Enum carmove As Integer 'create a Enum
left = 1
right = 2
End Enum
#End Region
#Region "form load"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load '
btnCreate.Text = "Create" 'write a text in label
btnLeft.Text = "Left" 'write a text in label
btnRight.Text = "Right" 'write a text in label
End Sub
#End Region
Introduction to Visual Basic .NET
APIIT SD INDIA Page 15
#Region "Function carcreate"
Public Function carcreate() As Integer 'function for create the
car
x = car1.pp.X
y = car1.pp.Y
k.FillRectangle(Brushes.Orange, x, y, 60, 40)
'create and fill the rectangle with pen and brush respectavily
k.FillRectangle(Brushes.WhiteSmoke, x + 10, 30, 40, 15)
'create and fill the rectangle with pen and brush respectavily
k.FillRectangle(Brushes.Orange, x, 50, 110, 20)
'create and fill the rectangle with pen and brush respectavily
k.FillEllipse(Brushes.Black, x + 20, 60, 20, 20)
'create and fill the rectangle with pen and brush respectavily
k.FillEllipse(Brushes.Black, x + 60, 60, 20, 20)
'create and fill the rectangle with pen and brush respectavily
End Function
#End Region
#Region "button Create"
Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCreate.Click
k = picRoad.CreateGraphics
'call the picture box to object
carcreate()
'call the carcreate function
btnCreate.Enabled = False 'set
the buttons as disabled after the click event of create button
btnLeft.Enabled = True 'set
the buttons as enabled after the click event of create button
btnRight.Enabled = True 'set
the buttons as enabled after the click event of create button
End Sub
#End Region
#Region "button Left"
Private Sub btnLeft_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLeft.Click
'x -= 20
'btnCreate_Click(sender, e)
draw = carmove.left 'set
the direction to left and move the car using the moveCar method
make() 'call
the make function
End Sub
#End Region
#Region "Button Right"
Private Sub btnRight_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnRight.Click
'x += 20
'btnCreate_Click(sender, e)
draw = carmove.right 'set
the direction to left and move the car using the moveCar method
make() 'call
the make function
End Sub
#End Region
Introduction to Visual Basic .NET
APIIT SD INDIA Page 16
#Region "Function make"
Public Sub make()
'create a function
k = picRoad.CreateGraphics 'call
the picture box to object
If draw = carmove.left Then 'use
if statement for moving the car in width of picturebox
If x >= picRoad.Width Then
x = 20
Else
k.Clear(Color.White)
x -= 40
a -= 40
car1.pp = New Point(x, y)
carcreate()
End If
ElseIf draw = carmove.right Then
If x >= picRoad.Width Then
x = 20
Else
k.Clear(Color.White)
x += 40
a += 40
car1.pp = New Point(x, y)
carcreate()
End If
End If
End Sub
#End Region
End Class
#End Region
Testing:-
Project Title Car class Testing Date 28/3/12
Test Case Name Car class
Test Case ID 2
Conducted By Raju Ranjan
Description A Car class is required to model cars
Testing Type Unit testing
Duration 2 day
Introduction to Visual Basic .NET
APIIT SD INDIA Page 17
Task 6 – Link Screen
Introduction: -
This new project is created to provide a welcome screen that leads to a main screen where the
user can choose which task they wish to complete:
Create Spike (task 3)
Identify flags (task 4)
Create a car (task 5)
The Welcome screen also allows the user to select a colour which is used for each of the task
screens. When a task is successfully completed; the task screen is hidden and may not be
selected again.
When the program starts, the Welcome screen (Task 2) will greet the user and allow them to
choose the colour for the application. This colour will be used as the background colour for
all the screens and for the Spike object when it is created.
The focus needs to be set to the Name textbox when the screen is first displayed and after the
user selects a new colour scheme.
LEARNING OUTCOME:-
We learned that to add forms to project, change form names and start up form .Also learned
to change start position of form and remove control box from form. How to add module to
project to declare Public variables .We also learned to create new form objects at runtime,
show forms at runtime, hide forms at runtime, close forms at runtime and show forms as
dialogs runtime.
Task 6:- Link Screens
Introduction to Visual Basic .NET
APIIT SD INDIA Page 18
Objective:-
add forms to project
change form names
change start up form
change start position of form
remove control box from form
add code module to project to declare Public variables
create new form objects at runtime
show forms at runtime
hide forms at runtime
close forms at runtime
show forms as dialogs at runtime
use focus to improve user interface
Planning:-
Firstly I plan to create a form and specify the form name and then declare all the
variables.
Then I plan to add forms to project and change the form names
I plan to remove control box from form and add code module to project to declare
public variables.
I plan to create new form objects at run time
I plan to show, hide ,close forms at runtime
I plan to show forms as dialogs at runtime
I plan to enable the Task button and disable Back button initially on each task screen.
I plan to disable the Task button and enabled Back button on completing each task
screen.
I plan to enable the Task button and disable Back button on failing to complet each
task screen.
I plan to show and hide Forms correctly. 4
Background of each form set to selected colour.
Introduction to Visual Basic .NET
APIIT SD INDIA Page 19
Design:-
Object Property Value
Form1 Name
Text
Frmlink
Link Classes
MenuStrip Text Tasks
Tool Strip Text Tasks
Link Screens File Tasks
Spike
Link Screens File Tasks
Spike Flags Car
Create spike
Identify Flags
Create Car
MenuStrip
ToolStrip
(Toolbar)
btnCreate btnLeft btnRight
Introduction to Visual Basic .NET
APIIT SD INDIA Page 20
Implementation:-
#Region "Class Link"
Public Class link
#Region "Form load"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.ControlBox = False 'make the control box
disabled
End Sub
#End Region
#Region "ToolStrip Button1"
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles ToolStripButton1.Click
Dim mdichild As New spike 'create a object
mdichild of form Spike
mdichild.MdiParent = Me 'set it to MdiParent of
mdichild form
mdichild.Show() 'display the new form
End Sub
#End Region
#Region "Tool Strip Button2"
Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles ToolStripButton2.Click
Dim mdichild As New flag 'create a object
mdichild of form flag
mdichild.MdiParent = Me 'set it to MdiParent
of mdichild form
mdichild.Show() 'display the new form
End Sub
#End Region
#Region "Tool Strip1"
Private Sub ToolStrip1_ItemClicked(ByVal sender As System.Object, ByVal
e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles
ToolStrip1.ItemClicked
Dim mdichild As New Form 'create a object mdichild
of form Test car
mdichild.MdiParent = Me 'set it to MdiParent
of mdichild form
mdichild.Show() 'display the new form
End Sub
#End Region
#Region "ToolStripButton3"
Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles ToolStripButton3.Click
Dim mdichild As New Form 'create a object mdichild
of form Test car
mdichild.MdiParent = Me 'set it to MdiParent
of mdichild form
mdichild.Show() 'display the new form
End Sub
#End Region
#Region "ToolStripMenuItem"
Private Sub CreateToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
CreateToolStripMenuItem.Click
Introduction to Visual Basic .NET
APIIT SD INDIA Page 21
Dim mdichild As New spike 'create a object
mdichild of form Spike
mdichild.MdiParent = Me 'set it to MdiParent
of mdichild form
mdichild.Show() 'display the new form
End Sub
#End Region
#Region "IdentifyFlagsToolStripMenuItem"
Private Sub IdentifyFlagsToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
IdentifyFlagsToolStripMenuItem.Click
Dim mdichild As New flag 'create a object
mdichild of form Spike
mdichild.MdiParent = Me 'set it to MdiParent
of mdichild form
mdichild.Show() 'display the new form
End Sub
#End Region
End Class
#End Region
MODULE CODE:-
Module Module1
Dim O As New Form1
Public Sub main()
O.ShowDialog()
End Sub
End Module
Introduction to Visual Basic .NET
APIIT SD INDIA Page 22
Testing:-
Project Title Welcome screen Testing Date 2/4/12
Test Case Name Welcome screen
Test Case ID 3
Conducted By Venkatesh Kumar
Description welcome screen that leads to a main screen
Testing Type Unit testing
Duration 2 day
Introduction to Visual Basic .NET
APIIT SD INDIA Page 23
Introduction to Visual Basic .NET
APIIT SD INDIA Page 24
CONCLUSION
After doing this project I conclude that how to implement the enable disable criteria. How it
works by clicking the button. The program must check to see if it is correct by seeing whether
the selected country matches the one held in the country variable and output an appropriate
message on the screen.
Also I conclude that how to crate car by using the graphic class. How it works by clicking
button. The program must check to see if it is correct by seeing whether it moves towards the
left and right by clicking the appropriate button.
In 6th task we conclude that how to link the screen. How it works by clicking the button.
Welcome screen will greet the user and allow them to choose the colour for the application.
This colour will be used as the background colour for all the screens and for object when it is
created. And the Welcome screen also allows the user to select a colour which is used for
each of the task screens and also when a task is successfully completed.
Introduction to Visual Basic .NET
APIIT SD INDIA Page 25
REFERENCES
1. Radio Button Events in VB.Net (No author) This website
available at
http://www.programmersheaven.com/mb/VBNET/339353/339353/ra
dio-button-events/
Last accessed on 25th March. 2012(Time: 2:30 pm)
2. An Introduction to Programming Using Visual Basic .net
(5th
edition) by David I. Schneider