CSI 101 Elements of Computing – Spring 2009
description
Transcript of CSI 101 Elements of Computing – Spring 2009
![Page 1: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/1.jpg)
CSI 101 Elements of Computing – Spring 2009
Lecture #11 – Structures of Visual BasicWednesday, March 18th
![Page 2: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/2.jpg)
Visual Basic Form
Primary means for user to interact with VB application
Contains Windows constructs to hold particular information We will discuss those later
Most applications have more than one form Particular events cause a new form to open
![Page 3: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/3.jpg)
Parts of a Form
Title Menu Bar
Contains words Produces dropdown menus
Tool bar Contains icons
Status bar Bottom Contains messages or other information
![Page 4: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/4.jpg)
Example of Parts of a Form
![Page 5: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/5.jpg)
Types of Forms Splash page
First screen to appear Main Menu (Switchboard)
Provides paths to major functions Most applications have screen menus as well
as menu bars Easy to follow logical path to get to particular
function Data Entry Reporting/Data Display
![Page 6: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/6.jpg)
Splash Page Example
![Page 7: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/7.jpg)
Main Menu – Simple Example
![Page 8: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/8.jpg)
Main Menu - Functional
![Page 9: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/9.jpg)
Submenu – Simple Example
![Page 10: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/10.jpg)
Branch Manager Selector ToolSearch Specifications
Which best describes selection requirements?Find competitor branches near PNC branch
Find branches near specific competitorº
º
Results
Should headquarters be included in search results?º No (default)º Yes
What about Denovo competitive branches?
IncludeExclude (default)
Only show Denovo
º
ºº
How many branches should be displayed in results?
20 Enter number between 1 and 50
How many miles radius should be searched?
10 Enter number between 1 and 50
Enter some PNC Branch infoCost Center:
Company #AddressCity State Zip
Bank Number:
Select a PNC Branch
Enter some Competitive Branch Info
Parent Bank Name Drop list
AddressCity State ZipSelect a Competitor Branch
Search Start Over
![Page 11: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/11.jpg)
Data Entry Sample – Text Boxes
![Page 12: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/12.jpg)
Branch Manager Selector ToolSearch Specifications Results
Cost Center / Bank:NoAddressCity State Zip
PNC Branch Deposit Growth Deposits Market Share
2007 2006 2005 2007 2006 2005 2007 2006 20057% 3%
Bank Name Distance (mi) Address City State Zip Deposit Growth Deposits Market Share2007 2006 2005 2007 2006 2005 2007 2006 2005
Print All Print SelectedChange Search
Denovo? HQ
Export All Export Selected
![Page 13: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/13.jpg)
Components of a Form
Objects Hold and display information
Events Activities that trigger code procedures to run
Code General declarations and Procedures
![Page 14: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/14.jpg)
Types of Procedures
Event Procedures Run when a particular event occurs “Attached” to a particular object
Subroutines Available to any code procedure via CALL
Functions Available to any code procedure
![Page 15: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/15.jpg)
Form Events Several, but here are the common ones:
Load – occurs when Form is requested Activate – occurs when Form is being
displayed in preparation for starting GotFocus – occurs when Form is displayed
and ready for user interaction LostFocus – occurs when user is done with
Form Deactivate – occurs when Form is closing Unload – occurs when Form is being removed
![Page 16: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/16.jpg)
Event Procedure Same structure as subroutines Name is object_event
Ex: Sub Form_Load() Starts with Scope
Public or Private Private by default
Means only available to form Some subroutines and functions you write can
be Public Available to any form or procedure in entire
application
![Page 17: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/17.jpg)
Form Event Procedure ExamplePrivate Sub Form_Load()
Dim boolFlag As BooleanDim intCount As IntegerDim strFilter As String
If strFilter <> "" Then:
End IfEnd Sub
![Page 18: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/18.jpg)
Form Objects
Plenty, but the ones we’ll be working with: Text box Label – Text Command button List box Combo box – List box plus text box Checkbox – True/False Option button – Select one of a group
![Page 19: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/19.jpg)
Object Elements
Properties Attributes of object Ex: Caption (“label” on command button) Properties can have properties
Ex: Font in text box Size, type, bold, etc
Events Event Code
![Page 20: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/20.jpg)
Object Properties
Referenced with dot notation Ex: CommandOK.Caption = “OK” Ex: Text1.Font.Size = 16
Can be referenced or changed by any procedure in Form
Different objects have different properties Full list of object’s properties can be seen in
the Visual Basic Developer Studio
![Page 21: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/21.jpg)
Message Box
Remember when I said Form was “primary” means of communicating with user?
Message Box is other Two forms:
MsgBox – Message to user (one-way) InputBox – Ask for data from user (two-way)
Both forms are created with a function
![Page 22: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/22.jpg)
MsgBox function
Causes a small popup window to appear in the middle of the screen
Has OK button for user to click to remove popup
MsgBox(<text>) Example:
MsgBox(“Error! Wrong Data Type”)
![Page 23: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/23.jpg)
InputBox function Causes popup window to appear in middle of
screen Contains a text box and OK button Text parameter clues user into what to enter User enters text and clicks OK Function returns the text in text box Example:
DIM Response As StringResponse = InputBox(“Enter number of
students”)
![Page 24: CSI 101 Elements of Computing – Spring 2009](https://reader035.fdocuments.in/reader035/viewer/2022081604/56813c79550346895da6103d/html5/thumbnails/24.jpg)
DoCmd object
Performs actions that trigger events Usually used to perform Form level actions
Like opening and closing forms Can be used in any procedure Example:
DoCmd.OpenForm “GetData”