15
MS Visual Basic 6 Walter Milner

MS Visual Basic 6 Walter Milner. VB 6 0 Introduction –background to VB, A hello World program 1 Core language 1 –Projects, data types, variables, forms,

Embed Size (px)

Citation preview

Page 1: MS Visual Basic 6 Walter Milner. VB 6 0 Introduction –background to VB, A hello World program 1 Core language 1 –Projects, data types, variables, forms,

MS Visual Basic 6

Walter Milner

Page 2: MS Visual Basic 6 Walter Milner. VB 6 0 Introduction –background to VB, A hello World program 1 Core language 1 –Projects, data types, variables, forms,

VB 6 • 0 Introduction

– background to VB, A hello World program• 1 Core language 1

– Projects, data types, variables, forms, controls , a calculator program• 2 Core language 2

– Conditional statements, exception handling, loops, arrays, debugging• 3 Core language 3

– Functions, sub-routines, parameter passing, modules, scope, lifetime• 4 Controls

– scrollbar, radio buttons, checkboxes, listboxes, timers, control arrays• 5 Graphics

– primitives and image files• 6 Forms

– Forms MDI, menus• 7 Files and databases

– adding controls, using data files, using databases• 8 Deployment

Page 3: MS Visual Basic 6 Walter Milner. VB 6 0 Introduction –background to VB, A hello World program 1 Core language 1 –Projects, data types, variables, forms,

Hello World in VB• Start VB• New Project – Standard .exe• Click the Button control on the ToolBox

and drag in the form• Double click the new button to invoke

the code editor• Enter code: • Click the Run button

Private Sub Command1_Click()MsgBox ("Hello world")End Sub

Exercise – try this out

Page 4: MS Visual Basic 6 Walter Milner. VB 6 0 Introduction –background to VB, A hello World program 1 Core language 1 –Projects, data types, variables, forms,

What is Visual Basic?

• Kemeny and Kurtz – Dartmouth College 1964

• For students – simple interpreted• Many versions since• MS VB versions – more power

not so simple• VBScript VBA .NET framework• RAD especially of user interface

Page 5: MS Visual Basic 6 Walter Milner. VB 6 0 Introduction –background to VB, A hello World program 1 Core language 1 –Projects, data types, variables, forms,

A very early version

Page 6: MS Visual Basic 6 Walter Milner. VB 6 0 Introduction –background to VB, A hello World program 1 Core language 1 –Projects, data types, variables, forms,

VB is not..

• Vendor independent• Platform independent• Based on a constant language definition• Separated definition and IDE implementation• Well documented• (IMO) suitable for very large projects which must

be maintained over a long period of time

Page 7: MS Visual Basic 6 Walter Milner. VB 6 0 Introduction –background to VB, A hello World program 1 Core language 1 –Projects, data types, variables, forms,

VB is ..

• easy to use

• suitable for RAD

• very marketable

Page 8: MS Visual Basic 6 Walter Milner. VB 6 0 Introduction –background to VB, A hello World program 1 Core language 1 –Projects, data types, variables, forms,

Building an application - steps

• Commercial – data driven – waterfall model – project management

• Science/engineering – underlying data and physical model, algorithms, testing

• In VB – RAD – focus on user interface prototyping and review.

Page 9: MS Visual Basic 6 Walter Milner. VB 6 0 Introduction –background to VB, A hello World program 1 Core language 1 –Projects, data types, variables, forms,

Building an application - forms

• VB uses 'form' to mean Window

• Info on form stored in a .frm file

• VB system draws form based on that info

• Forms can be treated like classes in OOP - later

Page 10: MS Visual Basic 6 Walter Milner. VB 6 0 Introduction –background to VB, A hello World program 1 Core language 1 –Projects, data types, variables, forms,

Building an application - controls

• Buttons, text boxes, labels, check boxes..• VB 'control' = user interface widget• Some invisible – timer• Controls have properties eg background color• Three kinds –

– standard– non-standard MS controls (common dialog, tab) and

3rd party– ActiveX controls written in-house

Page 11: MS Visual Basic 6 Walter Milner. VB 6 0 Introduction –background to VB, A hello World program 1 Core language 1 –Projects, data types, variables, forms,

Building an application - modularity

• Spaghetti programming, structured programming, OOP = increasing modularity

• In VB application constructed from modules = files in project-

• Form modules• BASIC modules• Class modules• Private and public control interaction

between modules

Page 12: MS Visual Basic 6 Walter Milner. VB 6 0 Introduction –background to VB, A hello World program 1 Core language 1 –Projects, data types, variables, forms,

Building an application - objects

• Some OOP in VB – not pure OOP

• objects = things eg a form

• class = type of object eg a form design

• property = data value associated with object

• method = something the object can do

Page 13: MS Visual Basic 6 Walter Milner. VB 6 0 Introduction –background to VB, A hello World program 1 Core language 1 –Projects, data types, variables, forms,

Building an application – example of OOP

Dim f As Form2Set f = New Form2

f.Show

f.BackColor = RGB(255, 0, 0)

Form2 is a class

f is an object – an instance of class Form2

the Form2 class has a method called show

It has a property called BackColor

Page 14: MS Visual Basic 6 Walter Milner. VB 6 0 Introduction –background to VB, A hello World program 1 Core language 1 –Projects, data types, variables, forms,

Event-driven programming

• Standard approach for GUIs• Contrast with old character interfaces – program

determines what happens• In GUI, the user triggers what application does

(mostly)• Event examples are key press, mouse move, timer

timeouts• Correspond to native Windows Messages (next

slide)• Event handler = a subroutine which will execute

when that event happens

Page 15: MS Visual Basic 6 Walter Milner. VB 6 0 Introduction –background to VB, A hello World program 1 Core language 1 –Projects, data types, variables, forms,

Windows Messages – Spy++