SlideServe
Menu
Préférences
© SlideServe · v2026

CP2028 Visual Basic Programming 2

odessa-cantrell avatar
28 diapositives · 609 Views · Nov 17, 2014

CP2028 Visual Basic Programming 2. Week 1 Lecture 1 & 2 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. CP2028 Module Aims and Objectives.

CP2028 Visual Basic Programming 2 - slide 1
01 / 28CP2028 Visual Basic Programming 2
1 / 17

Télécharger la présentation

CP2028 Visual Basic Programming 2
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. CP2028Visual Basic Programming 2 • Week 1 Lecture 1 & 2 • 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

  2. CP2028 Module Aims and Objectives • Reinforce the skills and knowledge gained in VB1. • Further develop programming abilities. • Topics covered include: • storing and accessing information in files • using Databases within VB. • File handling • error handling

  3. The Visual Basic module set. CP2028 VB2 CP1007 VB1 CP3013 App Dev in VB CP2030 VB For C++ CP1000 S.P. in C++

  4. Introduction to the Module [1]The Module Guide • 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.

  5. Introduction to the Module [2] • Timetable details (see module guide) • 2 x 1-hour lectures per week • Tutorial • Workshop • Weekly contents • Assessments • Coursework • Exam

  6. Review of V.B. Environment • Identify the components of the VB design environment? ? ? ? ? ?

  7. Review of V.B. Environment • Identify the components of the VB design environment? Menu Bar ? Code

  8. Review of V.B. Environment • Identify the components of the VB design environment? ? ? ? ? ?

  9. Review of V.B. Environment • Identify the components of the VB design environment? Menu Bar Project Window Control Toolbox Properties Window Form

  10. Visual Basic Program Structure. • Project File • ‘.VBP’ • Form Files • ‘.FRM’ • ‘.FRX’ • Modules • ‘.BAS’ • Custom Controls • ‘.VBX’ files

  11. Control Bar - How many controls can you identify? Standard Edition Professional Edition

  12. Control bar - Properties Run Time Vs Design Time (Startup Defaults) Name 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. Review of Event Driven Programming • Application program is composed of a number of subroutines, which are triggered by events within the environment. • Typical events include • Mouse-click • Keyboard use • Field value changes • Events happen to a control. • Mostly user generated events • Controls can also cause events

  14. Visual Basic Event Processing Trigger Event Code Executed

  15. Types of Events • Events can be classified as: • User generated • (e.g. command button click) • Computer generated • (e.g. specific time elapsed, from a timer control) • Program generated • (i.e. program explicitly generates an event from within the code)

  16. Visual Basic Events • The events that can happen to a control are pre-determined • Each type of control has a relevant set of events • The events that can happen to a Command Button

  17. Programming Practices • We need to consider • Control naming conventions • Variable naming conventions • Code documentation

  18. Scope of Variables Form1 General Declarations • Shows declarationsat form level, knownas: General Declarations • Shows variabledeclarations withinan event handler 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

  19. Scope • The general rule is to declare variables at the lowest possible level. • Ie Control level Form level Module level

  20. 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. Question calculator • Try the calculator with 5 divide 0 !!! • Why is the application not working ? • How can we correct the problem ?

  22. Solution

  23. Code

  24. code

  25. Static Variables • A static variable will hold its value when it goes out of scope:Sub Command1_Click() 'declare variablesDim iDimCount As IntegerStatic iStaticCount As Integer 'increment variables iDimCount = iDimCount + 1 iStaticCount = iStaticCount + 1'display variables Label3.Caption = Str$(iDimCount) Label4.Caption = Str$(iStaticCount)End Sub • A static variable can only be declared inside a procedure • Note the use of a comment • Note use of Str$ function

  26. Static Variables: Effects • The effect of using a static variable can be seen below: • This is has the same effect as if the variable had been declared at the form’s general declaration level • Except the scope is local to the procedure

  27. CP2028Visual Basic programming 2 • 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. End of Lecture Click House to Return to Main Menu