1 / 24

CSI 101 Elements of Computing – Spring 2009

CSI 101 Elements of Computing – Spring 2009. Lecture #11 – Structures of Visual Basic Wednesday, March 18 th. Visual Basic Form. Primary means for user to interact with VB application Contains Windows constructs to hold particular information We will discuss those later

nansen
Download Presentation

CSI 101 Elements of Computing – Spring 2009

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. CSI 101 Elements of Computing – Spring 2009 Lecture #11 – Structures of Visual Basic Wednesday, March 18th

  2. 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

  3. Parts of a Form • Title • Menu Bar • Contains words • Produces dropdown menus • Tool bar • Contains icons • Status bar • Bottom • Contains messages or other information

  4. Example of Parts of a Form

  5. 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

  6. Splash Page Example

  7. Main Menu – Simple Example

  8. Main Menu - Functional

  9. Submenu – Simple Example

  10. Branch Manager Selector Tool Search Specifications Results Which best describes selection requirements? Enter some PNC Branch info Find competitor branches near PNC branch Cost Center: º Bank Number: Find branches near specific competitor º Company # Should headquarters be included in search results? Address No (default) º City State Zip Yes º Select a PNC Branch What about Denovo competitive branches? Exclude (default) º Include º º Only show Denovo Enter some Competitive Branch Info How many branches should be displayed in results? Parent Bank Name Drop list Address 20 Enter number between 1 and 50 City State Zip How many miles radius should be searched? Select a Competitor Branch 10 Enter number between 1 and 50 Search Start Over

  11. Data Entry Sample – Text Boxes

  12. Branch Manager Selector Tool Search Specifications Results Cost Center / Bank:No Address PNC Branch City State Zip Deposit Growth Deposits Market Share 2007 2006 2005 2007 2006 2005 2007 2006 2005 7% 3% Deposit Growth Deposits Market Share Denovo? HQ Zip Bank Name Distance (mi) Address City State 2007 2006 2005 2007 2006 2005 2007 2006 2005 Change Search Export All Export Selected Print All Print Selected

  13. Components of a Form • Objects • Hold and display information • Events • Activities that trigger code procedures to run • Code • General declarations and Procedures

  14. 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

  15. 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

  16. 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

  17. Private Sub Form_Load() Dim boolFlag As Boolean Dim intCount As Integer Dim strFilter As String If strFilter <> "" Then : End If End Sub Form Event Procedure Example

  18. 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

  19. 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

  20. 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

  21. 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

  22. 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”)

  23. 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 String Response = InputBox(“Enter number of students”)

  24. 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”

More Related