1 / 35

CP2030 VBFC Visual Basic For C++ Programmers Lecture 1

CP2030 VBFC Visual Basic For C++ Programmers Lecture 1. Back To Index Module Introduction Structure Of Module What Is Visual Basic The Visual Basic Environment Introduction To Controls, Events, Properties and Methods A Simple Visual Basic Program. Introduction To The Module Staff Names.

azure
Télécharger la présentation

CP2030 VBFC Visual Basic For C++ Programmers Lecture 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CP2030 VBFCVisual Basic For C++ ProgrammersLecture 1 Back To Index Module Introduction • Structure Of Module • What Is Visual Basic • The Visual Basic Environment • Introduction To Controls, Events, Properties and Methods • A Simple Visual Basic Program

  2. Introduction To The ModuleStaff Names • D.I.Beardsmore MU401 1461 CM1940 • P.I.Wilson MU217 1806 CM1949

  3. Structure Of The Module • Module consists of formal Lectures, Tutorials and Workshops • Lectures - 2 hrs approx. Notes will be provided • Tutorials - 1 hour In most cases questions will be set - time will be made available for students to raise problems, and review lectures, etc • Workshops - 1 hours Help with WS questions. Assessment sign offs.

  4. Module Information • Refer to the timetable for Workshops and Tutorials. • WorkShop and Tutorial groups. IT IS IMPORTANT TO KEEP TO YOUR ALLOCATED GROUPS • Book list : • Visual Basic Quick Tutor - R Smythe • An Intro To Programming Using Visual Basic 4 - D. Schneider • Mastering VB - S.Saxon, D Saxon

  5. Module Assessment • Assessment 70% Four Assessment questions. (Assessment 1 consists of a number of smaller questions) • Examination 30%

  6. Aims of The Module • Provides an introduction to Windows programming - event driven programming. • Design AND Programming in a Graphical User Interface Environment • Introduces many of the most widely used controls - enables students to fully develop a stand alone application. • Develops professional programming skills • Prepares students for industrial year

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

  8. What is Visual Basic? • Event-driven programming language • Powerful, Windows-based, screen designer..... • ....linked to underlying functionality in subroutines/functions • Increased functionality via third party VBX(Visual Basic Extension - 16 bit) and OCX (Object Linking and Embedding - 32 bit) • Rapid application development

  9. Background to Visual Basic • BeginnersAll-purposeSymbolicInstructionCode • A simple programming language • Developed in 1963 as a resident language • Simple Language made it very popular • Most machines have own version of BASIC • DOS based (not windows) • Many version developed GWBASIC, CPMBASIC,… MS-QuickBASIC(1982)

  10. Windows Programming • Visual Basic developed in-house at Microsoft • Windows based • Applications developed within an environment • Powerful windows design for Graphical User Interfaces (GUIs). • Simple but powerful coding language • Quick to produce applications • Currently the most popular language for Windows applications

  11. Differences between VB & C++ • Students to add notes

  12. Similarities between VB & C++ Students to add notes

  13. Visual Basic Environment • Components of the VB design environment? Menu Bar Project Window Control Toolbox Properties Window Form

  14. VB Environment: Menu Bar • 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 Toolbar

  15. VB Environment: Project Window

  16. VB Environment: Properties Window

  17. VB Environment: Control Toolbox Picture Text Box Command Button Option/Radio Button List Box Vertical Scroll Bar Drive List Box File List Box Line Data Control Grid Pointer Label Group Frame Check Box Combo Box Horizontal Scroll Bar Timer Directory List Box Shape Image Common Dialog OLE

  18. VB Environment: Context Sensitive Help • Context sensitive help is very useful • Select the item control that you want help on • Press the F1 key F1

  19. Visual Basic Program Overview Design Tools Screen Editor Code Editor Run/Debug Other tools:Paintbrushetc.. Toolbox Control/Event Property Box Third PartyControlsVBX/OCX Colour Palette Compiler/Application Menu Design

  20. Introduction To Controls, Events, Properties & Methods • 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 • if code has been attached it is executed, • otherwise default processing takes place • Controls - Properties • all controls have appropriate properties • such as Height, Name, Colour • properties can be changed either at design-time or at run-time

  21. Visual Basic Events • eg. Mouse Click, Key Press, Got Focus, Timer, etc. • Control events are pre-determined by the programmer • Each type of control has a relevant set of events • Eg. Events thatcan happen to a command button

  22. Event Driven Programs • In normal programming your application is always in control • In GUI(Graphical User Interface) programming your applications provide a number of service routines which are triggered as required by the operating system • Events happen to a control/object • mostly user generated events • controls themselves can also cause events • Events are pre-set/pre-programmed

  23. Control - Form(s) • At design stage controls are placed on the form • During execution the form control acts like any other window- maximize, minimize, etc • An application can be make up from a number of forms • Like all other controls the form has properties - caption name, size, colour, etc

  24. Events and Visual Basic • Visual Basic is event-driven • You start with your user interface by drawing graphical Controls on Forms • You then add program code for each of these controls which will be run (or triggered) when a particular event is generated • Example event: Command Button Click Trigger Event Code Executed

  25. 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)

  26. Controls Properties • 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 • 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 • Properties can be changed either at design time or at run time

  27. Changing Properties at Design Time • By selecting the properties window properties can be set to values at design time • A drop down list of the controls currently on the form, allows the selection of a control so its properties can be edited • All the properties of that control are shown below, where they can be selected for editing • The currently selected property of the selected control is shown in the edit window where it can be modified

  28. Changing Properties at Run Time • To change a control’s property you assign the new property to it: • Command1.Enabled = FalseLabel1.ForeColor = QBColor(4) • To access a control on another form you should use the form name to prefix the property name:Form1.Command1.Caption = “New Caption” Control Name Property Form Name Control Name Property

  29. Controls Methods • A method is a routine which operates on a control, for example control_name.SetFocus would make control_name the currently selected control. • There are many methods available, we will only use a few of them • The Events, Properties and Methods for controls can be found under the controls description in Help. i.e. select a control then press F1 to get the help for a control.

  30. Controls - Label and Text Boxes • Labels are used for text output : Titles, Messages, and Prompts - screen text that the user cannot change. eg. Label1.Caption = “Heading For Program 1” • Text Boxes are used for both text input and output. eg. Text1.Text = “Output to Text box1” sName = Text2.Text (Text Input covered in week2)

  31. Control - CommandWriting 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 • We have to decide the control and its event procedure we want the user to use to invoke the code • Command buttons are often used to invoke code. Normally for command buttons we use their click event • In actual fact you can write code for any event from any control.

  32. Developing a Simple VB Program • Students to add notes

  33. Visual Basic Program Structure • Project File • ‘.MAK’ • Form Files • ‘.FRM’ • ‘.FRX’ • Modules • ‘.BAS’ • Custom Controls • ‘.VBX’ files • Save As... • Possible problem...

  34. Saving The Project • When you come to save the project you will be saving a number of files: • FORM1.FRMthe form itself • PROJECT1.MAKthe project make file • The best way to organise your projects is by keeping each project in a separate directory.You can create new directories using file manager • 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!

  35. Question • Create an application to either display a students name with either First name followed by Second name OR Second name followed by first name.

More Related