Download presentation
Presentation is loading. Please wait.
Published byNoreen Page Modified over 9 years ago
1
CSE2207/CSE3007 Rapid Applications Programming with Windows Week 3
2
CSE2207/CSE3007 Week 3 zPrototyping, step by step zDesigning an Application ythe GUI and W95 conventions yTOE charts zInterface Navigation, Form Handling zWriting Code: the Code Editor zProgramming Fundamentals
3
Prototyping, Step by Step zStart by laying out the forms zSome basic guidelines: yHumans don’t think in numbers (let the computer create primary keys) yUse lists for user choices (no validation!) xsupport the typing of the first few letters yNever force the user to use or enter codes xa displayed code is a defeat!
4
Prototyping, Step by Step... zEstablish Standards yPlacement of “Back”, “Exit”, “Cancel” buttons? yFonts, colors, use of “Help”, function keys ySize, placement of forms? yContent of menus? xAll forms must display exactly the same menus always, with the inappropriate options disabled mnuFileSave.Enabled = False yNames of objects
5
Prototyping, Step by Step... zBreak up the Job into Tasks yThe user’s mental conceptualisation occurs here ySit with the user and sketch out forms, form linkages yGet the user to talk about standard tasks and procedures. Exceptions should come later. ySub-tasking is necessary where tasks take >1 screen yUse Frames, Tabbed Dialog control to isolate different tasks on the same form ySupport closure: user should never have to remember information across screens: so repeat information across forms if necessary
6
Prototyping, Step by Step... zPass Screen Ownership to the User yThe user can enter data in any sequence, make mistakes etc yConsider/discuss when, how editing/validation should take place: xonly when the user passes control to the program by clicking the “Done” or “Save” buttons? xAs soon as the entry field loses focus? xOk to use masked edit controls? yRemember. you are not the boss y(BUT, it is YOUR RESPONSIBILITY to ensure that the data entered by the user is valid before you use it or write it to the database)
7
Designing an Application zIdentify the tasks for ythe whole application yeach form/screen zDecide forms relationships, interaction zFor each form yspecify tasks, objects(controls) involved in those tasks, events for those objects (TOE chart) ystart with a paper sketch, and involve the user
8
Designing an Application... zTOE chart can be later used in form-level testing zCategories of Form Tasks: yInput from user/database/files yValidation, calculation yOutput to screen/files/printer/database yStart/End processing yRepeated tasks yInteraction with user, other forms zPrinting Documentation, forms y(Design Time) File|Print then Form Image, Code, or Form as Text (see Example 4) y(Run Time) frmInput.PrintForm
10
The GUI and W95 zBasic Windows ‘skill-set’ yclicking, selecting, dragging, menu selection zUser controls program flow ycomplete visual representation of salient program features and choices xcontinual display only for options in continual use xplace options in menu bar to avoid clutter yprovide feedback xhourglass cursor, gauge, status bar, dialog box
11
Naming Objects zVB will automatically name each object you create e.g. Project1, Form1, List1 etc zALWAYS change the default name as soon as you create the object zNaming conventions: ythe first 3 characters indicate the type of object yremaining characters represent its purpose: frmSplash, txtName, cmdQuit, fraNewDetails zNaming Rules: ymust begin with a letter yconsists only of letters, numbers, underscore y40 characters or less
12
Object Naming Conventions zhttp://msdn.microsoft.com/library/ devprods/vs6/vbasic/vbcon98/ vbconobjectnamingconventions.htm
13
Form Handling... zWhen a VB app starts, the startup form is displayed, then the following events occur Initialize: yoccurs ONCE when an instance of a form is created; yuse to initialize data e.g. read a file into an array ythe window, controls do not yet exist. Load: yoccurs ONCE, when form is loaded into memory yuse to initialize controls, data, but cannot set focus to a control (not visible yet) yGeneral/Declarations section is automatically executed
14
Form Handling Activate: yoccurs whenever the form has focus yoccurs before a related GotFocus() event ytriggered by user click, a form’s Show, SetFocus methods; Use e.g. to write code to highlight the text in a particular text box. zChange form’s BorderStyle, StartUpPosition, MaxButton, MinButton, Visible properties zUse a Splash Screen to ‘mask’ setup tasks (Example 2) zA VB application can begin with a startup form or startup procedure called Sub Main() (See Examples 1,2) zA VB Application can begin with a startup form or startup procedure called Sub Main() (See Examples 1, 2) yProject|Project Properties|General Tab|Startup Object
15
Form Handling... zAn event-driven application ends when: yall forms are closed yno code is executing (any hidden forms?) (See Ex3) yEnd ends the app. immediately: no further code is processed, no further events occur zWhen a form is unloaded, 3 events occur: yQueryUnload: occurs in all forms before any are unloaded; cancel unload via the Cancel parameter yUnload: Occurs as each form is unloaded Also has a Cancel parameter. yTerminate: indicates that VB has removed the form and its module from memory.
16
Interface Styles (Introduction) zMultiple Document Interface yAn interface which allows the user to view and work with multiple windows (forms) which are all displayed within a single container (parent) form e.g. MS Word, Excel yMax of 2 active windows (1 parent, 1 child) zSingle Document Interface yAn interface which allows the user to view and work with multiple windows (forms) which are independent of each other, and can occupy the whole screen if required. (e.g. WordPad)
17
Interface Styles (Introduction)... zThe Explorer-style Interface yA single window containing two panes or regions, usually consisting of a tree or hierarchical view on the left and a display area on the right, as in the Microsoft Windows Explorer. yThis type of interface lends itself to navigating or browsing large numbers of documents, pictures, or files. zExperiment with styles in the App. Wizard
18
Programming Fundamentals zVariables, Data Types, Constants, zScope zModules, Sub Procedures, Function Procedures
19
Variables zVariables can be used for storing data/information which is not stored in a control on the user interface. zVariables hold values that can be changed when the program runs. zA variable has a name (the word used to refer to the variable in your code) and a data type. zConvention: use first 3 characters of name to indicate data type (some developers also indicate scope e.g. Dim pintTotal as Integer)
20
Data Types zThe Variant data type handles all types of fundamental data and converts between them automatically. zInteger% (int) 2 bytes –32,768 to 32,767 zLong& (lng) 4 bytes –2,147,483,648 to 2,147,483,647 zSingle! (sng) 4 bytes(Floating point) zDouble# (dbl) 8 bytes (Floating point) zCurrency@ (cur) 8 bytes15.4 zString$ (str)1 byte per character 0 to approximately 65,500(F) + 10 for Var Lgth0 to 2 billion (V) zByte(byt)1 byte 0 to 255 zBoolean (bln) 2 bytes True or False zDate (dat)8 bytesJanuary 1, 100 to December 31, 9999 zObject (obj) 4 bytesAny Object reference zVariant (vnt) 16-22 bytes + 1 byte for each character
21
Data Types... Examples intEmpAge% = 24‘Implicit variable declaration vntEmpAge = 24‘VB default - Variant Dim intEmpAge As Integer intEmpAge = 24 Dim datBirthday As Date datBirthday = #April 2, 1974# Dim curCost as Currency curCost = 2999.95 Dim strName, strAddress as String strAddress = txtStreet.Text & “Street” Dim strID As String * 7 ‘ A fixed-length string with room for exactly 7 characters Static lngTotalStudents as Long
22
Converting an Expression Function/Ret Type CBoolBoolean CbyteByte CCurCurrency CDateDate CDblDouble CInt Integer CLngLong CSng Single CStrStringCVErrError CVarVariant (See Example 5)
23
Constants Constants are used to hold values that will not change for the duration of the program zLiteral constant e.g. 5 zSymbolic constant ya memory location whose CONTENTS do not change for the duration of the program ycode is more readable, and easier to modify yValues assigned may NOT contain variables, functions xPublic Const conSngPi as Single = 3.141593 xConst conHeading = “Lucky Lou’s Betting Agency” OR xConst HEADING = “Lucky Lou’s Betting Agency”
24
Variables and Constants zMust begin with a letter, and contain only letters, numbers and the _ character. zMust be 40 or fewer characters in length. zCannot be a reserved word zForce VB to check for undeclared variables: yManually enter ‘Option Explicit’ in the General Declarations section of EVERY form and code module OR (recommended!!) yTools|Options|EditorTab|Require Variables Declaration
25
Scope of Variables and Constants A local (or procedure level) variable is declared with Dim in a procedure, is visible only from its own procedure, and exists in memory only when the procedure is running. EXCEPTION: Static variables will retain their value zA module-level variable is declared in the module’s General (object) Declarations (Proc) Section, using the Private keyword. Can be used by every procedure in the module. zA global variable is declared with the Public keyword in the General Declarations Section of a Module. It is available to every line of code in your application.
26
Scope of Variables and Constants zAll variables declared in the general section of a Standard (Code) Module: yare public throughout the whole application, unless the Private keyword is used yare available for the life of the application zAll variables declared in the general section of a Form Module: yare public throughout the whole application, unless the Private keyword is used ypublic form variables are treated as properties of the form and continue to exist even after the form is unloaded (Example 6)
27
Modules, Procedures and Functions zVB modules: Form, Standard (or Code), Class yProject|Add|Module zAll contain code that can be shared at various levels of scope in the application. (Example 6) zCode is written as an Event, General procedure yEvent procedure is triggered by the user, system yGeneral procedure must be called by your program zFunction Procedures and Sub procedures are types of General procedures ynamed sequence of statements executed as a single unit yFunction returns a value, Sub(procedure) does not
28
Using Procedures, Functions z(In a Code Module or in the General Declarations Section of a Form, if application has only 1 form) Sub Multiply(intFirst As Integer, intSecond As Integer) lngGlobalVar = inFirst * inSecond End Sub zThen call it: Call Multiply(3, 5) Function Multiply(ByVal intFirst As Integer, ByVal intSecond as Integer) As Long Multiply = CLng(intFirst * intSecond) End Function zThen call it: lngProduct = Multiply(236, 9999) zSee Example 7
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.