Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week 1 Lecture 1 Slide 1 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton CP2028 Visual Basic Programming 2 v Week.

Similar presentations


Presentation on theme: "Week 1 Lecture 1 Slide 1 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton CP2028 Visual Basic Programming 2 v Week."— Presentation transcript:

1 Week 1 Lecture 1 Slide 1 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton CP2028 Visual Basic Programming 2 v Week 1 Lecture 1 & 2 – Introduction to the module u The VB module set u Contents and structure of this module – Review of the Visual Basic environment – Review of programming practices – Variables & Scope

2 Week 1 Lecture 1 Slide 2 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton CP2028 Module Aims and Objectives v Reinforce the skills and knowledge gained in VB1. v Further develop programming abilities. v Topics covered include: – storing and accessing information in files – using Databases within VB. – File handling – error handling

3 Week 1 Lecture 1 Slide 3 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton The Visual Basic module set. CP1007 VB1 CP2028 VB2 CP3013 App Dev in VB CP2030 VB For C++ CP1000 S.P. in C++

4 Week 1 Lecture 1 Slide 4 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton Introduction to the Module [1] The Module Guide v The module consists of 12 weeks of study, plus a revision week. v As in VB1 the aim is to increase your skills and knowledge in program design and development. v Visual Basic is the target language, but the skills gained are applicable to other languages.

5 Week 1 Lecture 1 Slide 5 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton Introduction to the Module [2] v Timetable details (see module guide) – 2 x 1-hour lectures per week – Tutorial – Workshop v Weekly contents v Assessments – Coursework – Exam

6 Week 1 Lecture 1 Slide 6 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton Review of V.B. Environment v Identify the components of the VB design environment? ? ? ? ? ?

7 Week 1 Lecture 1 Slide 7 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton Review of V.B. Environment v Identify the components of the VB design environment? Code Menu Bar ?

8 Week 1 Lecture 1 Slide 8 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton Review of V.B. Environment v Identify the components of the VB design environment? ? ? ? ? ?

9 Week 1 Lecture 1 Slide 9 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton Review of V.B. Environment v Identify the components of the VB design environment? Form Menu Bar Control Toolbox Project Window Properties Window

10 Week 1 Lecture 1 Slide 10 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton Visual Basic Program Structure. v Project File – ‘.VBP’ v Form Files – ‘.FRM’ – ‘.FRX’ v Modules – ‘.BAS’ v Custom Controls – ‘.VBX’ files

11 Week 1 Lecture 1 Slide 11 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton Control Bar - How many controls can you identify? Standard Edition Professional Edition

12 Week 1 Lecture 1 Slide 12 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton Control bar - Properties Name Run Time Vs Design Time (Startup Defaults) Setting control positions when place on form Vs via the properties window What if we want to resize our forms do we resize controls? How? Are there tools to do it?

13 Week 1 Lecture 1 Slide 13 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton Review of Event Driven Programming v Application program is composed of a number of subroutines, which are triggered by events within the environment. – Typical events include u Mouse-click u Keyboard use u Field value changes v Events happen to a control. – Mostly user generated events – Controls can also cause events

14 Week 1 Lecture 1 Slide 14 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton Visual Basic Event Processing Trigger Event Code Executed

15 Week 1 Lecture 1 Slide 15 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton Types of Events v Events can be classified as: v User generated –(e.g. command button click) v Computer generated –(e.g. specific time elapsed, from a timer control) v Program generated –(i.e. program explicitly generates an event from within the code)

16 Week 1 Lecture 1 Slide 16 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton Visual Basic Events v The events that can happen to a control are pre- determined v Each type of control has a relevant set of events v The events that can happen to a Command Button

17 Week 1 Lecture 1 Slide 17 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton Programming Practices v We need to consider – Control naming conventions – Variable naming conventions – Code documentation

18 Week 1 Lecture 1 Slide 18 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton Scope of Variables v Shows declarations at form level, known as: General Declarations v Shows variable declarations within an event handler Form1 General Declarations Sub Command1_Click () Sub Command2_Click () Dim sName1 As String Dim iNum1 As Integer Dim sName2 As String Dim iNum2 As Integer Dim sName3 As String Dim iNum3 As Integer Available variables: sName1, sName2, iNum1, iNum2 Available variables: sName1, sName3, iNum1, iNum3

19 Week 1 Lecture 1 Slide 19 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton Scope v The general rule is to declare variables at the lowest possible level. v Ie Control level Form level Module level

20 Week 1 Lecture 1 Slide 20 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton Question Calculator Create a front end for a simple calculator, You should be able to accept two numbers and perform addition, subtraction, multiplication and division.

21 Week 1 Lecture 1 Slide 21 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton Question calculator v Try the calculator with 5 divide 0 !!! v Why is the application not working ? v How can we correct the problem ?

22 Week 1 Lecture 1 Slide 22 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton Solution

23 Week 1 Lecture 1 Slide 23 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton Code

24 Week 1 Lecture 1 Slide 24 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton code

25 Week 1 Lecture 1 Slide 25 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton Static Variables  A static variable will hold its value when it goes out of scope: Sub Command1_Click() 'declare variables Dim iDimCount As Integer Static iStaticCount As Integer 'increment variables iDimCount = iDimCount + 1 iStaticCount = iStaticCount + 1 'display variables Label3.Caption = Str$(iDimCount) Label4.Caption = Str$(iStaticCount) End Sub v A static variable can only be declared inside a procedure v Note the use of a comment v Note use of Str$ function

26 Week 1 Lecture 1 Slide 26 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton Static Variables: Effects v The effect of using a static variable can be seen below: v This is has the same effect as if the variable had been declared at the form’s general declaration level v Except the scope is local to the procedure

27 Week 1 Lecture 1 Slide 27 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton CP2028 Visual Basic programming 2 v Week 1 - Summary – Structure of this module and its position in the VB module set. – Review of VB environment. – Review of event-driven programming

28 Week 1 Lecture 1 Slide 28 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton End of Lecture Click House to Return to Main Menu


Download ppt "Week 1 Lecture 1 Slide 1 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton CP2028 Visual Basic Programming 2 v Week."

Similar presentations


Ads by Google