Академический Документы
Профессиональный Документы
Культура Документы
Introduction to the module The VB module set Contents and structure of this module Review of the Visual Basic environment Review of programming practices
Variables & Scope
storing and accessing information in files using Databases within VB. File handling error handling
CP2028 VB2
CP2030 VB For C++
The module consists of 12 weeks of study, plus a revision week. As in VB1 the aim is to increase your skills and knowledge in program design and development. Visual Basic is the target language, but the skills gained are applicable to other languages.
Weekly contents
Assessments
Coursework Exam
Menu Bar
?
Code
CP2028 Visual Basic Programming 2 The VB Team Copyright University of Wolverhampton
Project Window
Form
CP2028 Visual Basic Programming 2 The VB Team Copyright University of Wolverhampton
Properties Window
Week 1 Lecture 1 Slide 9
Project File
.VBP
.FRM .FRX .BAS .VBX files
Form Files
Modules
Custom Controls
Standard Edition
Professional Edition
Application program is composed of a number of subroutines, which are triggered by events within the environment.
Trigger Event
Code Executed
Types of Events
Computer generated
(e.g. specific time elapsed, from a timer control)
Program generated
(i.e. program explicitly generates an event from within the code)
Programming Practices
We need to consider
Control naming conventions Variable naming conventions
Code documentation
Scope of Variables
Shows declarations at form level, known as: General Declarations Shows variable declarations within an event handler
Form1 General Declarations Dim sName1 As String Dim iNum1 As Integer Sub Command1_Click () Dim sName2 As String Dim iNum2 As Integer Available variables: sName1, sName2, iNum1, iNum2 Sub Command2_Click () Dim sName3 As String Dim iNum3 As Integer Available variables: sName1, sName3, iNum1, iNum3
Scope
Ie
Control level Form level Module level
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.
Question calculator
Try the calculator with 5 divide 0 !!! Why is the application not working ? How can we correct the problem ?
Solution
Code
code
Static Variables
A static variable will hold its value when it goes out of scope: Sub Command1_Click()
'declare variables
A static variable can only be declared inside a procedure Note the use of a comment Note use of Str$ function
This is has the same effect as if the variable had been declared at the forms general declaration level Except the scope is local to the procedure
The VB Team Copyright University of Wolverhampton
Week 1 - Summary
Structure of this module and its position in the VB module set. Review of VB environment. Review of event-driven programming
End of Lecture