Вы находитесь на странице: 1из 25

Introduction to Visual Basic .

NET

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 Raju Ranjan (Pt1082221)

SUBMITTED TO MS.SAKSHI POPLI (MODULE LECTURER)

APIIT SD INDIA

Page 1

Introduction to Visual Basic .NET

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: Raju Ranjan PT1082221

Submitted to:Ms.Sakshi Popli Module lecturer

APIIT SD INDIA

Page 2

Introduction to Visual Basic .NET

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

Planning18 Design..19 Implementation.20 Testing..22 Conclusion23 References24 APIIT SD INDIA Page 3

Introduction to Visual Basic .NET

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)

APIIT SD INDIA

Page 4

Introduction to Visual Basic .NET

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.

APIIT SD INDIA

Page 5

Introduction to Visual Basic .NET

Design:-

Flag Button

Picture Box

Radio Button

Lable

APIIT SD INDIA

Page 6

Introduction to Visual Basic .NET


`

Object Form1 Label1 RadioButton1 RaioButton2 RadioButton3 RadiButton4 RadioButton5 RadioButton6 RadioButton7 Button

Property Name Text Name Text Name Text Name Text Name Text Name Text Name Text Name Text Name Text Name Text

Value Frmflag Identify Flags lblMessage btnBelgium Belgium btnCanada Canada btnChina China btnFinland Finland btnFrance France btnSudan Sudan btnZambia Zambia btnFlag Flag

Implementation:#Region "Identify flags" Public Class Form1 Dim country As String Dim randomnum As Integer Dim randum As New Random #Region "disabler function" Public Sub disabler() radiobutton rdbCanada.Enabled = True rdbBelgium.Enabled = True rdbChina.Enabled = True rdbFinland.Enabled = True rdbSudan.Enabled = True rdbZambia.Enabled = True rdbFrance.Enabled = True End Sub #End Region #Region "form load" 'declear country as string variable 'declear randomnum as integer 'declear randum as Randum 'declear a function for disabeling the 'make 'make 'make 'make 'make 'make 'make radio radio radio radio radio radio radio button button button button button button button disabled disabled disabled disabled disabled disabled disabled

APIIT SD INDIA

Page 7

Introduction to Visual Basic .NET


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 which country is selected 'use select statement to determine

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-icon250x250.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

APIIT SD INDIA

Page 8

Introduction to Visual Basic .NET


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

APIIT SD INDIA

Page 9

Introduction to Visual Basic .NET


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 event of radio button rdbSudan.Checked = False btnFlag.Enabled = True event of radio button End Sub #End Region #Region "RadioButton Zambia" 'panel is disabled after the click 'it unchecked the radio button 'flag button is enabled after click

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 event of radio button rdbZambia.Checked = False btnFlag.Enabled = True event of radio button End Sub #End Region End Class #End Region 'panel is disabled after the click 'it unchecked the radio button 'flag button is enabled after click

APIIT SD INDIA

Page 10

Introduction to Visual Basic .NET


Testing:Project Title Test Case Name Test Case ID Conducted By Description Testing Type Duration Identify Flag Identify Flag 1 Raju Ranjan Display the flag of a randomly selected country Unit testing 2 day Testing Date 24/3/12

APIIT SD INDIA

Page 11

Introduction to Visual Basic .NET

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.

APIIT SD INDIA

Page 12

Introduction to Visual Basic .NET

Design:btnCreate Task Bar Create Left Right btnLeft btnRight

picRoad

APIIT SD INDIA

Page 13

Introduction to Visual Basic .NET

Object Form1 Button1 Button2 Button3 PictureBox1

Property Name Text Name Text Name Text Name Text Name Text

Value frmcar Test car btnCreate Create btnLeft Left btnRight Right 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

APIIT SD INDIA

Page 14

Introduction to Visual Basic .NET


#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

APIIT SD INDIA

Page 15

Introduction to Visual Basic .NET


#Region "Function make" Public Sub make() 'create a function k = picRoad.CreateGraphics the picture box to object If draw = carmove.left Then 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

'call 'use

Testing:Project Title Test Case Name Test Case ID Conducted By Description Testing Type Duration Car class Car class 2 Raju Ranjan A Car class is required to model cars Unit testing 2 day Testing Date 28/3/12

APIIT SD INDIA

Page 16

Introduction to Visual Basic .NET

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

APIIT SD INDIA

Page 17

Introduction to Visual Basic .NET


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.

APIIT SD INDIA

Page 18

Introduction to Visual Basic .NET

Design:btnCreate btnLeft btnRight

Link Screens File Tasks Create spike


Spike

Link Screens File Tasks

Identify Flags Create Car

Spike

Flags

Car

ToolStrip (Toolbar)

MenuStrip

Object Form1 MenuStrip Tool Strip

Property Name Text Text Text

Value Frmlink Link Classes Tasks Tasks

APIIT SD INDIA

Page 19

Introduction to Visual Basic .NET 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

APIIT SD INDIA

Page 20

Introduction to Visual Basic .NET


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

APIIT SD INDIA

Page 21

Introduction to Visual Basic .NET


Testing:Project Title Test Case Name Test Case ID Conducted By Description Testing Type Duration Welcome screen Welcome screen 3 Venkatesh Kumar welcome screen that leads to a main screen Unit testing 2 day Testing Date 2/4/12

APIIT SD INDIA

Page 22

Introduction to Visual Basic .NET

APIIT SD INDIA

Page 23

Introduction to Visual Basic .NET


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.

APIIT SD INDIA

Page 24

Introduction to Visual Basic .NET 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

APIIT SD INDIA

Page 25

Вам также может понравиться