Copyright © Don Kussee - 1120-Intro # 541 CNS 1120 Copyright © Don Kussee 1120-Intro.PPT.
Copyright © Don Kussee 1120-Ch2 #531 CNS 1120 Chapter 2 Project Structure and Tools 1120-Ch2.PPT.
-
Upload
mariah-sullivan -
Category
Documents
-
view
235 -
download
0
description
Transcript of Copyright © Don Kussee 1120-Ch2 #531 CNS 1120 Chapter 2 Project Structure and Tools 1120-Ch2.PPT.
Copyright © Don Kussee 1120-Ch2 #53
1
CNS 1120Chapter 2
Project Structure and Tools1120-Ch2.PPT
2Copyright © Don Kussee 1120-Ch2 #53
Structure of VB projects
ProjectResource
fileClass
modules*Code modules
Forms
Generaldeclarations
sectionGeneral
subprocedures
Controls
Properties Eventprocedures
Generaldeclarations
sectionGeneral
subprocedures
* The structure of class modules has been omitted for clarity.
0+
1
0 or 1
0+ 1+
1+ 0+
0+0+
0+1
3Copyright © Don Kussee 1120-Ch2 #53
Structure of VB projects
ProjectForms
Generaldeclarations
sectionGeneral
subprocedures
Controls
Properties Eventprocedures
0+
10+ 1+
1+ 0+
Displayed “windows”
User interface object
Instructions to the computer
The definition of what isincluded in the program.
Code
Copyright © Don Kussee 1120-Ch2 #53
4
Terms
• Project - all of the Forms, controls, code necessary for a program to run.
• Form - the screen we will design on, and the user will see.
• Controls or Objects - GUI objects attached to the form
• Expressions - code - the instructions that the computer will follow.
Copyright © Don Kussee 1120-Ch2 #53
5
TOPE chartTask-Object-Event
• Task Object Property Event
Copyright © Don Kussee 1120-Ch2 #53
6
VB Programming Process
1 Understand the user’s requirements2 Analyze - TOPE chart for inputs & outputs3 Develop the GUI forms to be used
– Place the controls on the forms4 Write code to hook the controls together5 Test and debug the program6 Create the executable program.
Copyright © Don Kussee 1120-Ch2 #53
7
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.
8Copyright © Don Kussee 1120-Ch2 #53
The VB environment
Form frm 53 Properties, 31 Events, 21 Methods
Copyright © Don Kussee 1120-Ch2 #53
10
53 Properties Propertiesfrm
Copyright © Don Kussee 1120-Ch2 #53
11
FormEvents
31 Events
Copyright © Don Kussee 1120-Ch2 #53
12
Form methods 21 Methods
• Circle, Line, Point• Cls, Hide, Show, Refresh• Popup menu • Drag, DragOver• Move left, [top, [width, [height]]]• SetFocus, GotFocus, LostFocus
Copyright © Don Kussee 1120-Ch2 #53
13
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• Form1.BackColor = vbRed• Form1.Label2.Forecolor = vbRed
Copyright © Don Kussee 1120-Ch2 #53
14
Objects, Classes, Controls
• Over 4000 different controls available - we will use about 10
• Many special VBX on the internet• NextPage Corp’s VBX is $ 5,000• VB assists in building of new Classes -
ActiveX - VBX - OCX• CNS 3200 includes these concepts
Copyright © Don Kussee 1120-Ch2 #53
15
Controls, Objects, Classes
Text Box
Control Button
Label
Copyright © Don Kussee 1120-Ch2 #53
16
Programs
• Series of steps for the computer to follow• Computer can be told to do only 5 things
– Input - Get data from outside– Output - Supply data to outside– Process - Add, Subtract, Multiply, etc– Select - Equal to, less than, between – Loop - Repeat some steps of a program
Copyright © Don Kussee 1120-Ch2 #53
17
Controls, Objects, Classes
• Label output• Text Box input• Command Button trigger
• Pickup truck - Red Dodge V-10 long bed• Bird - Gray - “chi-cog-o” - top-feather - walks• Computer- 300 Mhertz- 64M RAM- 17” screen
Copyright © Don Kussee 1120-Ch2 #53
18
Controls7 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
Copyright © Don Kussee 1120-Ch2 #53
19
Primary Controls for Input…………... Output………...
• Text box• Command button• MsgBox / InputBox• Menu• Check box• Option buttons• List / Combo box• Scroll bars
• Text box• MsgBox• Label• Image• Picture
Copyright © Don Kussee 1120-Ch2 #53
20
Controls - Object - Class
• Properties that can change it’s appearance– Size, shape, location, look, color
• Events that it can respond to– Click, mouse over, drag
• Methods - things it can do– Move, Connect, Load, Update
Copyright © Don Kussee 1120-Ch2 #53
21
Real world objectsproperties, events, methods
• Cashier• Woodpecker• Grass• Computer• Student• Professor• Dog Vs Cat• Airplane
• Jet ski• Bicycle• Bicycle rider• Olympic Bicycle racer• Car• Duck• Ostrich• Duckbilled platypus
Copyright © Don Kussee 1120-Ch2 #53
22
VB Tool BoxLabel tool
Used to label other controls, and provide output.
Copyright © Don Kussee 1120-Ch2 #53
23
Label lbl
• 48 Properties– Appearance & location
• 23 Events– Change– Click– DblClick– Load
• 10 Methods– Move– Refresh– ZOrder
Copyright © Don Kussee 1120-Ch2 #53
24
Label
Copyright © Don Kussee 1120-Ch2 #53
25
Label properties
• Name - used in code procedures• Caption - displayed on the form or control
• Enabled - does it work• Visible - can you see it
• Usual event - None
Copyright © Don Kussee 1120-Ch2 #53
26
Command Button cmd
• 17 Events – Cause an user event to occur - Click usually
• 24 Methods• 32 Properties for each instantiation
– Appearance• Size, Shape, Location, Colors, Font, Style
– Caption - The title on the button– Picture property - an image on the button
Copyright © Don Kussee 1120-Ch2 #53
27
Command Button properties
• Name - used in code procedures• Caption - displayed on the button• Picture - displayed on the button• Enabled - does it work• Visible - can you see it
• Usual event - Click
Copyright © Don Kussee 1120-Ch2 #53
28
CommandButton.Caption changed
Copyright © Don Kussee 1120-Ch2 #53
29
Events
Copyright © Don Kussee 1120-Ch2 #53
30
Processing code for Command Button
• Note: header and indentation
Copyright © Don Kussee 1120-Ch2 #53
31
Header required for every program
Rem *********************************
Rem *** Program name ***‘ *** Programmers name ***‘ *** Date of program ***‘ *** Description of the program ***‘ ********************************
Copyright © Don Kussee 1120-Ch2 #53
32
Demo of design mode
• Add a control 3 ways– Double click, Draw, Copy & Paste
• Delete control• Change properties 3 ways F4
– Type over– Additional menu …– Choice items
Copyright © Don Kussee 1120-Ch2 #53
33
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
Copyright © Don Kussee 1120-Ch2 #53
34
Other VB Windows
• Form Layout Window Figure 2.25• Project Explorer Window Figure 2.26• Help Windows Figure 2.29 - 32
Copyright © Don Kussee 1120-Ch2 #53
35
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
36Copyright © Don Kussee 1120-Ch2 #53
The VB environment
PropertiesThe currently selected control is named Command1
The setting for Command1’s Caption property is Command1
Property list
Object box
Copyright © Don Kussee 1120-Ch2 #53
38
Code window
Procedure boxObject box
Code area
Copyright © Don Kussee 1120-Ch2 #53
39
Code Window
• Each procedure has an Object_Event
40Copyright © Don Kussee 1120-Ch2 #53
The VB environment
Menu barTool bar
Toolbox
Code window
Form window Properties window
Project window
Copyright © Don Kussee 1120-Ch2 #53
41
Naming objects
• When projects get big (Project 2 Page 59 uses 17 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
Copyright © Don Kussee 1120-Ch2 #53
42
Some primary controls• Command button - allows user to cause event
– 32 properties 24 Methods 17 events cmd• Form - The window that the user sees
– 52 properties 21 Methods 31 events frm• Label - outputs information to the user
– 48 properties 10 Methods 18 events lbl• Timer - an event based on time
– 7 properties 0 Methods 1 event tmr
Copyright © Don Kussee 1120-Ch2 #53
43
Some primary controls• Frame - groups controls into a group
– 34 properties 6 Methods 13 events fra
Copyright © Don Kussee 1120-Ch2 #53
44
Command Button properties
• 32 Properties 24 Methods 17 Events• Name - used in code procedures• Caption - displayed on the button• Picture - displayed on the button• Enabled - does it work• Visible - can you see it• Usual event - Click
Copyright © Don Kussee 1120-Ch2 #53
45
Printing Visual Basic programs
Copyright © Don Kussee 1120-Ch2 #53
46
File Names
• Win95 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
Copyright © Don Kussee 1120-Ch2 #53
47
Win95 Standard File Extensions
• VBP VB Project• FRM VB Form• VBX controls on form• BAS VB Module• CLS VB Class• MDB MS Access• TXT Generic text• EXE Executable
• DAT Data • LOG Recorded event• COM Commands• BAT Batch • BIN Binary • BAK Backup• JPG Graphics• SYS System
Copyright © Don Kussee 1120-Ch2 #53
48
Saving Visual Basic Programs
1 Create a folder with a descriptive name2 In the folder, create a VB program3 Save the Form, Classes, Code, Resources4 Save the Project
• Save frequently• Backup often
Copyright © Don Kussee 1120-Ch2 #53
49
Saving Visual Basic Programs
Copyright © Don Kussee 1120-Ch2 #53
50
File type change
Copyright © Don Kussee 1120-Ch2 #53
51
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 .vbx• Zero or more Code modules -often zero .bas• Zero or more Class modules -often zero .cls• Zero or more Resource files -often zero .res
Copyright © Don Kussee 1120-Ch2 #53
52
Assignments
• Lightening 1• Exchange Rate• Café Don• Lightening 2• Color choice• Data types
Copyright © Don Kussee 1120-Ch2 #53
53
Computer Terms
• Syntax• Semantic• Keyword• Code• Control• Object• Properties• Methods• Events
• Run time error• Syntax error• Logical error• Default value• Form• lbl Prefix• cmd Prefix• Empty string