Universiti Kuala Lumpur Malaysia France Institute

16
8/14/2019 Universiti Kuala Lumpur Malaysia France Institute http://slidepdf.com/reader/full/universiti-kuala-lumpur-malaysia-france-institute 1/16

Transcript of Universiti Kuala Lumpur Malaysia France Institute

Page 1: Universiti Kuala Lumpur Malaysia France Institute

8/14/2019 Universiti Kuala Lumpur Malaysia France Institute

http://slidepdf.com/reader/full/universiti-kuala-lumpur-malaysia-france-institute 1/16

Page 2: Universiti Kuala Lumpur Malaysia France Institute

8/14/2019 Universiti Kuala Lumpur Malaysia France Institute

http://slidepdf.com/reader/full/universiti-kuala-lumpur-malaysia-france-institute 2/16

2

U

NIVERS

ITIKUAL

A

LUMPUR

M

alaysi a

FranceI

nstit

ute

Module page

 The aim of this module is to introduce students to

computer programming using a modern programminglanguage. You do not need any previous programmingexperience to take this module.

Assessment:

Course work 60% Final Examination 40%

 The coursework comprises:

1. A programming assignment 1 10%

2. A programming assignment 2 20%3. Programming Test 20%

4. Attendance/Quizes 10%

5. Final Examination 40%

Page 3: Universiti Kuala Lumpur Malaysia France Institute

8/14/2019 Universiti Kuala Lumpur Malaysia France Institute

http://slidepdf.com/reader/full/universiti-kuala-lumpur-malaysia-france-institute 3/16

3

U

NIVERS

ITIKUAL

A

LUMPUR

M

alaysi a

FranceI

nstit

ute

Programming

“All the world’s a stage,

And all the men and women merely players;  They all have their exits and their entrances,

And one man in his time plays many parts,”

As you like it, W Shakespeare

Whenever a computer program is written an attempt is made torepresent some aspect of the world.

Not all of the world but just a small part of interest – the problemdomain.

 The model will have various components or actors that interact

with each other to simulate the behaviour of the problem domain. In programming these components are called variables or 

objects, and we shall be concerned with Object OrientedProgramming (OOP).

Page 4: Universiti Kuala Lumpur Malaysia France Institute

8/14/2019 Universiti Kuala Lumpur Malaysia France Institute

http://slidepdf.com/reader/full/universiti-kuala-lumpur-malaysia-france-institute 4/16

4

U

NIVERS

ITIKUAL

A

LUMPUR

M

alaysi a

FranceI

nstit

ute

Programming environment

Most programming is now performed with aid 

of a software development tool. This is

sometimes referred to as an IDE –

integrated development environment , or 

workbench. This provides the means to write,

edit and compile code, and run and debug 

 programs

Visual Basic programs will be created within

an environment called  Visual Studio.

Page 5: Universiti Kuala Lumpur Malaysia France Institute

8/14/2019 Universiti Kuala Lumpur Malaysia France Institute

http://slidepdf.com/reader/full/universiti-kuala-lumpur-malaysia-france-institute 5/16

5

U

NIVERS

ITIKUAL

A

LUMPUR

M

alaysi a

FranceI

nstit

ute

rogram eve opment nv ronment –cont’d

When Studio is first opened, it displays a dialogue to allowyou to select the required developer tool from the profilelist, i.e. Visual Basic.Net.

It then displays the Start Page.

At this point it is recommended that Tools/Options is used toindicated the default folder in which to store VB projects.

Suggest you create a

folder called  StudID 

within your fsb23103

folder, enter the folder 

then copy the pathfrom the address bar 

to the options entry. 

Page 6: Universiti Kuala Lumpur Malaysia France Institute

8/14/2019 Universiti Kuala Lumpur Malaysia France Institute

http://slidepdf.com/reader/full/universiti-kuala-lumpur-malaysia-france-institute 6/16

6

U

NIVERS

ITIKUAL

A

LUMPUR

M

alaysi a

FranceI

nstit

ute

Environment - New Project

 

● Click on the New 

Project  icon on

the command bar ● Select  Windows

 Application and give project a

name, say  

fsb23103sess1p1.● Ok .

Page 7: Universiti Kuala Lumpur Malaysia France Institute

8/14/2019 Universiti Kuala Lumpur Malaysia France Institute

http://slidepdf.com/reader/full/universiti-kuala-lumpur-malaysia-france-institute 7/16

7

U

NIVERS

ITIKUAL

A

LUMPUR

M

alaysi a

FranceI

nstit

ute

Environment – cont’d

 

The design view  of theIntegrated Development 

Environment (IDE) is then

opened. This comprises

several windows, a menu 

bar and tool bar:

Page 8: Universiti Kuala Lumpur Malaysia France Institute

8/14/2019 Universiti Kuala Lumpur Malaysia France Institute

http://slidepdf.com/reader/full/universiti-kuala-lumpur-malaysia-france-institute 8/16

8

U

NIVERS

ITIKUAL

A

LUMPUR

M

alaysi a

FranceI

nstit

ute

Environment windows

• Form1.vb [Design] window contains a form, Form1, where the program’s graphical user interface (GUI) willbe displayed. This is used for data entry and output.Usually referred to as ‘the form’.

• Properties – Form1 records/displays the form’sattributes or properties, e.g. colour, font style, size, etc.

 These are listed alphabetically (by selecting the alphabetictab) or categorically (by selecting the categorised tab) byaccessibility, appearance, behaviour, etc.

• Solution Explorer – fsb23103sess1p1.

  window groups the project’s files by type. Usually referredto as ‘the Solution window’, it has buttons to:

View code – displays a window for writing VB code

View Designer – displays the form

Show all files – lists all files in the current project

Page 9: Universiti Kuala Lumpur Malaysia France Institute

8/14/2019 Universiti Kuala Lumpur Malaysia France Institute

http://slidepdf.com/reader/full/universiti-kuala-lumpur-malaysia-france-institute 9/16

9

U

NIVERS

ITIKUAL

A

LUMPUR

M

alaysi a

FranceI

nstit

ute

Environment windows – cont’d

• The Toolbox containscontrols used to customiseforms. Controls are pre-packaged components thatare incorporated in formsand allow programs to becreated more quickly.

Page 10: Universiti Kuala Lumpur Malaysia France Institute

8/14/2019 Universiti Kuala Lumpur Malaysia France Institute

http://slidepdf.com/reader/full/universiti-kuala-lumpur-malaysia-france-institute 10/1610

U

NIVERS

ITIKUAL

A

LUMPUR

M

alaysi a

FranceInstit

ute

A simple program

- to display the text “Welcome to Visual basic” on a form.

1. Create New Project called fsb23103sess1p1 and open theIDE in design view.

If necessary, click 

the

Form1.vb[Design] 

or Form design

icon.

In Form properties window:

2. Set the form’s title bar  -

in properties window set  

Text  to:

Sess1: A Simple

Program.

Page 11: Universiti Kuala Lumpur Malaysia France Institute

8/14/2019 Universiti Kuala Lumpur Malaysia France Institute

http://slidepdf.com/reader/full/universiti-kuala-lumpur-malaysia-france-institute 11/1611

U

NIVERS

ITIKUAL

A

LUMPUR

M

alaysi a

FranceInstit

ute

A simple program – cont’d

Ensure that the form “has the focus” by clicking on the formthen

3. Set form’s default font property to Arial, bold, 14pt.

4. Set the font colour, forecolor, to a dark colour

5. Change the form’s background colour - choose a lightcolour from custom palette

6. If not already open, click on the Toolbox icon and then thedrawing pin symbol for it to remain open

6. Add a label control to the form – Click and drag the toolboxlabel control to the form and position it using thesizing handles.

7. To set the label display – type the required text: Welcometo Visual Basic! in the label’s Text property.

8.   Name the label – in name property, type lblWelcome.

By convention label names will commence with ‘lbl’.

Page 12: Universiti Kuala Lumpur Malaysia France Institute

8/14/2019 Universiti Kuala Lumpur Malaysia France Institute

http://slidepdf.com/reader/full/universiti-kuala-lumpur-malaysia-france-institute 12/1612

U

NIVERS

ITIKUAL

A

LUMPUR

M

alaysi a

FranceInstit

ute

Simple program - cont’d

Reposition and size the label using the size handles on theform. Note the change of values in the positionproperty.

9. Save the project 

10. To run the program click the Start icon on the menu bar.

11.During ‘runtime’ a window called Output is visible and thisprovides information on any errors that occur.

 The program is terminated by closing the form window.

Page 13: Universiti Kuala Lumpur Malaysia France Institute

8/14/2019 Universiti Kuala Lumpur Malaysia France Institute

http://slidepdf.com/reader/full/universiti-kuala-lumpur-malaysia-france-institute 13/1613

U

NIVERS

ITIKUAL

A

LUMPUR

M

alaysi a

FranceInstit

ute

Simple program - cont’d

Start icon

To close

Note: a program canbe edited only in 

‘ Design’ view 

Page 14: Universiti Kuala Lumpur Malaysia France Institute

8/14/2019 Universiti Kuala Lumpur Malaysia France Institute

http://slidepdf.com/reader/full/universiti-kuala-lumpur-malaysia-france-institute 14/16

Page 15: Universiti Kuala Lumpur Malaysia France Institute

8/14/2019 Universiti Kuala Lumpur Malaysia France Institute

http://slidepdf.com/reader/full/universiti-kuala-lumpur-malaysia-france-institute 15/1615

U

NIVERS

ITIKUAL A

LUMPUR

M

alaysi a

FranceInstit

ute

Example

- to provide an exit to a program.

1. Drag a button on to thefsb23103sess1p1 form; positionand size it.

2. Change its Name property tocmdExit and its Text property toExit.

3. Double click on the button toreveal

Page 16: Universiti Kuala Lumpur Malaysia France Institute

8/14/2019 Universiti Kuala Lumpur Malaysia France Institute

http://slidepdf.com/reader/full/universiti-kuala-lumpur-malaysia-france-institute 16/1616

U

NIVERS

ITIKUAL A

LUMPUR

M

alaysi a

FranceInstit

ute

Example – cont’d

 The code window contains:

  Private Sub cmdExit_Click( ByVal sender AsSystem.Object, _ 

ByVal e As System.EventArgs) Handles cmdExit.Click

 This begins the event procedure definition and is calledthe procedure definition header.

 The bracketed content is a syntax requirement.

 The definition ends with: End Sub

On the clicking the button we require the program to

terminate and the form to close. To achieve this type 

Close( ) before the End Sub.