Presentation is loading. Please wait.

Presentation is loading. Please wait.

Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-1 Visual Basic Projects Project Structure and VB’s Programming Tools chapter TWO.

Similar presentations


Presentation on theme: "Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-1 Visual Basic Projects Project Structure and VB’s Programming Tools chapter TWO."— Presentation transcript:

1

2 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-1 Visual Basic Projects Project Structure and VB’s Programming Tools chapter TWO

3 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-2 Visual Basic Projects Project Structure and VB’s Programming Tools After studying this topic you should be able to: Design and construct simple complete applications from scratch. Explain the structure of VB projects. List the characteristics of several VB controls. Identify the purpose of each major component of the VB environment. Explain basic programming practices that contribute to the readability of programs.

4 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-3 Design mode Run mode Break mode Programmer Project Visual Basic runs under the Windows operating system. The programmer uses VB to create the application. The application under construction in VB is called a “project.”

5 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-4 The programmer periodically saves the project to disk. Design mode Run mode Break mode Programmer Project

6 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-5 The programmer periodically saves the project to disk. The completed project is made into an “executable file,” which VB stores on disk. This file contains the finished application program. Design mode Run mode Break mode Programmer Project

7 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-6 The programmer periodically saves the project to disk. The completed project is made into an “executable file,” which VB stores on disk. This file contains the finished application program. The application is delivered to the user. Design mode Run mode Break mode Programmer User Project Finished Application

8 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-7 START Programmer User Finished Application The application program runs under the Windows operating system independently of VB.

9 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-8 The application program runs under the Windows operating system independently of VB. The executable file cannot be modified; if changes to the application program are required, the programmer must use VB to open the project files, modify the project, and then make a new executable file. START Programmer User Finished Application

10 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-9 The VB environment  Menu bar Tool barProject Explorer window Properties window Form Layout windowForm Designer window FormCode windowToolbox The VB environment

11 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-10 The Properties window  Object boxCurrently selected control is named CCCommand1 Sort tabs Property list The setting for Command1’s Caption property is Command1 Description pane

12 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-11 The Code window  Object box Procedures/ Events box Code areaFull Module View button Procedure View button Margin indicator bar

13 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-12 Break button switches from run mode to break mode. End button switches to design mode. Design mode Start button switches to run mode. Run mode Break mode Toolbar buttons for switching VB’s mode 

14 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-13 The Project Explorer Window  View Code button View Object button Toggle Folders button Forms, code modules, class modules and resource files belonging to the project

15 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-14 Structure of VB projects  Project * The structure of class modules has been omitted for clarity. General declarations section Forms General sub procedures Controls Properties Event procedures 1+ 1 0+ 1+ 0+ Code modules General declarations section General sub procedures 0+ 1 Class modules* 0+ Resource file 0 or 1

16 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-15 Structure of VB projects  Project Forms General declarations section General sub procedures Controls Properties Event procedures 0+ 1 1+ 0+ Displayed “windows” User interface object Instructions to the computer The definition of what is included in the program. Code

17 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-16 Visual Basic Modes Design –where most of our time will be spent –Form, the tool bar and tool box are available –Properties window is available –Code window is available Run - where we will test & evaluate the program Break - where we can debug our problems Compile –The program we will give to the user.

18 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-17 Form frm 53 Properties, 31 Events, 21 Methods

19 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-18 53 Properties Form Properties

20 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-19 Form Events 31 Events

21 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-20 Form methods 21 Methods Circle, Line, Point Cls, Hide, Show, Refresh Popup menu Drag, DragOver Move left, [top, [width, [height]]] SetFocus, GotFocus, LostFocus

22 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-21 Properties of Forms Caption - Name at the top of the form BackColor - Systems colors or Palette WindowState - 0 = Just like design(Default) 1 = Minimized, 2 = Maximized Name used in code also is default file name Icon becomes the default exe icon Form1.BackColor = vbRed

23 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-22 Controls 7 general categories Trigger 3 Timer, Command button Input 6 TextBox, Combo, Scroll Output 4 Label, Textbox, Image Organize 3 Form, Frame Graphic 2 Line, Circle Data Access 4 Combo, Data Integration 1 OLE

24 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-23 Procedure vs Event programming Procedures... the old way, it starts at the top and runs to the bottom every time - how a traffic light works, cars or no cars Event new way store clerks - demand –The program waits, then reacts to some event. –Reacts differently to different events. –Event procedure is the detail code for the computer to follow

25 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-24 Events

26 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-25 Processing code for Command Button Note: indentation

27 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-26 Command1 Instructions... When the user clicks on the command button with the mouse, the computer executes the command button’s Click event procedure. Command1’s Click event procedure When the user moves the mouse while the mouse pointer is positioned over the command button, the computer executes the command button’s MouseMove event procedure. Command1’s MouseMove event procedure

28 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-27 Stopping Visual Basic Include an Exit key in every project Ctr + Break will stop processing Run menu Square Alt + R Gets run menu - choose E

29 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-28 Naming objects When projects get big (Project 2 Page 55 uses 14 labels) naming objects with meaningful names is very helpful when writing code and provides documentation. Not all objects need to be re-named All object names should use the three letter abbreviation of the object type

30 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-29 File Names Windows allows 256 characters –Except only ~ ? * : –But in DOS mode only 1st 6 letters are used –There is an extension Form including controls and code.FRM Changes to controls on the form.FRX Project listing forms and others files.VBP

31 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-30 Standard File Extensions VBP VB Project FRM VB Form VBW VB Form info VBX controls on form BAS VB Module CLS VB Class TXT Generic text EXE Executable DAT Data LOG Recorded event COM Commands BAT Batch BIN Binary BAK Backup JPG Graphics SYS System

32 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-31 Expanded VP program parts Projects - grouping of forms & files & code One and only one project.vbp Zero or more Forms - usually one.frm –modification of controls on the form.vbw Zero or more Code modules -often zero.bas Zero or more Class modules -often zero.cls Zero or more Resource files -often zero.res

33 Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-32 Stop Watch Lab Exercise Chapter 2 Programming Problem 3 –Identify user requirement –Design the application –Construct the application


Download ppt "Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., 1999 2-1 Visual Basic Projects Project Structure and VB’s Programming Tools chapter TWO."

Similar presentations


Ads by Google