
ad82209df6a23d1134b4855947e55b31.ppt
- Количество слайдов: 35
CP 2030 VBFC Visual Basic For C++ Programmers Lecture 1 Back To Index Module Introduction Structure Of Module v What Is Visual Basic v The Visual Basic Environment v Introduction To Controls, Events, Properties and Methods v A Simple Visual Basic Program v CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 1
Introduction To The Module Staff Names v D. I. Beardsmore MU 401 1461 CM 1940 v P. I. Wilson MU 217 1806 CM 1949 CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 2
Structure Of The Module v Module consists of formal Lectures, Tutorials and Workshops v Lectures - 2 hrs approx. Notes will be provided v Tutorials - 1 hour In most cases questions will be set - time will be made available for students to raise problems, and review lectures, etc v Workshops - 1 hours Help with WS questions. Assessment sign offs. CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 3
Module Information v Refer to the timetable for Workshops and Tutorials. v Work. Shop and Tutorial groups. IT IS IMPORTANT TO KEEP TO YOUR ALLOCATED GROUPS Book list : v Visual Basic Quick Tutor - R Smythe v An Intro To Programming Using Visual Basic 4 - D. Schneider v Mastering VB - S. Saxon, D Saxon v CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 4
Module Assessment v Assessment 70% Four Assessment questions. (Assessment 1 consists of a number of smaller questions) v Examination 30% CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 5
Aims of The Module v Provides an introduction to Windows programming - event driven programming. v Design AND Programming in a Graphical User Interface Environment v Introduces many of the most widely used controls - enables students to fully develop a stand alone application. v Develops professional programming skills v Prepares students for industrial year CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 6
The Visual Basic module set. CP 1007 VB 1 CP 2028 VB 2 CP 2030 VB For C++ CP 3013 App Dev in VB CP 1000 S. P. in C++ CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 7
What is Visual Basic? Event-driven programming language v Powerful, Windows-based, screen designer. . . v. . linked to underlying functionality in subroutines/functions v Increased functionality via third party VBX(Visual Basic Extension - 16 bit) and OCX (Object Linking and Embedding - 32 bit) v Rapid application development v CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 8
Background to Visual Basic Beginners All-purpose Symbolic Instruction Code v A simple programming language v Developed in 1963 as a resident language v Simple Language made it very popular v Most machines have own version of BASIC v DOS based (not windows) v Many version developed GWBASIC, CPMBASIC, … MSQuick. BASIC(1982) v CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 9
Windows Programming Visual Basic developed in-house at Microsoft v Windows based v Applications developed within an environment v Powerful windows design for Graphical User Interfaces (GUIs). v Simple but powerful coding language v Quick to produce applications v v Currently the most popular language for Windows applications CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 10
Differences between VB & C++ v Students to add notes CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 11
Similarities between VB & C++ Students to add notes CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 12
Visual Basic Environment v Components of the VB design environment? Menu Bar Project Window Control Toolbox Form CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Properties Window Lec 1 P 13
VB Environment: Menu Bar v The Menu Bar consists of 3 elements the – Title Bar, which holds the name of application, default if Microsoft Visual Basic [design] – Menu Bar, this is the link to Visual Basic’s menu facilities, each menu option drops down into sub-menus – Toolbar, contains icons which give access to the more commonly used commands (which are also available through the menu bar) Title bar Menu Bar CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Toolbar Lec 1 P 14
VB Environment: Project Window CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 15
VB Environment: Properties Window CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 16
VB Environment: Control Toolbox Pointer Label Group Frame Check Box Combo Box Horizontal Scroll Bar Timer Directory List Box Picture Text Box Command Button Option/Radio Button List Box Vertical Scroll Bar Drive List Box File List Box Shape Line Image Data Control Common Dialog OLE CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Grid Lec 1 P 17
VB Environment: Context Sensitive Help Context sensitive help is very useful v Select the item control that you want help on v Press the F 1 key v F 1 CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 18
Visual Basic Program Overview Design Tools Screen Editor Toolbox Code Editor Control/Event Run/Debug Other tools: Paintbrush etc. . Property Box Colour Palette Menu Design Compiler/ Application CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Third Party Controls VBX/OCX Lec 1 P 19
Introduction To Controls, Events, Properties & Methods v Controls - Processing Graphical objects which can be placed onto a form (window) – Controls have pre-defined ‘events’ eg. mouse click – Code can be attached to an event – When an event occurs u if code has been attached it is executed, u otherwise default processing takes place v Controls - Properties – all controls have appropriate properties u such as Height, Name, Colour – properties can be changed either at design-time or at run-time CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 20
Visual Basic Events eg. Mouse Click, Key Press, Got Focus, Timer, etc. v Control events are pre-determined by the programmer v Each type of control has a relevant set of events v v Eg. Events that can happen to a command button CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 21
Event Driven Programs v In normal programming your application is always in control v In GUI(Graphical User Interface) programming your applications provide a number of service routines which are triggered as required by the operating system v Events happen to a control/object – mostly user generated events – controls themselves can also cause events v Events are pre-set/pre-programmed CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 22
Control - Form(s) At design stage controls are placed on the form v During execution the form control acts like any other windowmaximize, minimize, etc v An application can be make up from a number of forms v Like all other controls the form has properties - caption name, size, colour, etc v CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 23
Events and Visual Basic is event-driven v You start with your user interface by drawing graphical Controls on Forms v You then add program code for each of these controls which will be run (or triggered) when a particular event is generated v Example event: Command Button Click v Trigger Event Code Executed CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 24
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) CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 25
Controls Properties v Properties describe the characteristics of a control, these can be – physical characteristics such as height, width and colour – or its current state such as enabled, or links definitions to other applications v Note the name and caption properties of a control have the same default values but are actually different. – The name is what code uses to reference the control, whereas – the caption is purely what is written on the control so the user can identify it Good idea to rename controls to meaningful names v Properties can be changed either at design time or at run time CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 26
Changing Properties at Design Time By selecting the properties window properties can be set to values at design time v A drop down list of the controls currently on the form, allows the selection of a control so its properties can be edited v All the properties of that control are shown below, where they can be selected for editing v The currently selected property of the selected control is shown in the edit window where it can be modified v CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 27
Changing Properties at Run Time v To change a control’s property you assign the new property to it: Control Name Property v Command 1. Enabled = False Label 1. Fore. Color = QBColor(4) v To access a control on another form you should use the form name to prefix the property name: Form Name Control Name Property Form 1. Command 1. Caption = “New Caption” CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 28
Controls Methods v A method is a routine which operates on a control, for example control_name. Set. Focus would make control_name the currently selected control. v There are many methods available, we will only use a few of them v The Events, Properties and Methods for controls can be found under the controls description in Help. i. e. select a control then press F 1 to get the help for a control. CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 29
Controls - Label and Text Boxes v Labels are used for text output : Titles, Messages, and Prompts - screen text that the user cannot change. eg. Label 1. Caption = “Heading For Program 1” v Text Boxes are used for both text input and output. eg. Text 1. Text = “Output to Text box 1” s. Name = Text 2. Text (Text Input covered in week 2) CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 30
Control - Command Writing Code Under an Event When we want our program to do something we have to write code to do it, code is written under event procedures v We have to decide the control and its event procedure we want the user to use to invoke the code v Command buttons are often used to invoke code. Normally for command buttons we use their click event v v In actual fact you can write code for any event from any control. CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 31
Developing a Simple VB Program v Students to add notes CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 32
Visual Basic Program Structure v Project File – ‘. MAK’ v Form Files – ‘. FRM’ – ‘. FRX’ v Modules – ‘. BAS’ v Custom Controls – ‘. VBX’ files v Save As. . . – Possible problem. . . CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 33
Saving The Project v When you come to save the project you will be saving a number of files: – FORM 1. FRM – PROJECT 1. MAK the form itself the project make file v The best way to organise your projects is by keeping each project in a separate directory. You can create new directories using file manager v If you are working on the harddisk/network drive then you should make sure that you copy the files back onto your floppy disk when you’ve finished! CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 34
Question v Create an application to either display a students name with either First name followed by Second name OR Second name followed by first name. CP 2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton Lec 1 P 35
ad82209df6a23d1134b4855947e55b31.ppt