Savings Account using Class Modules Please use speaker notes for additional information!

Slides:



Advertisements
Similar presentations
Chapter 3: Using Variables and Constants Programming with Microsoft Visual Basic 2005, Third Edition.
Advertisements

Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Chapter 11: Classes and Objects
VB Class with Access Data Please see speaker notes for additional information!
Visual Basic: An Object Oriented Approach 6: Object Modelling.
OOP-Creating Object-Oriented Programs
VBA Modules, Functions, Variables, and Constants
instance variables property procedures for the mintQuantity instance variable.
Creating Object Oriented Programs Object oriented (OO) terminology Class vs. object Instantiate an object in a project Understand Class_Initialize / Terminate.
SUNY Morrisville-Norwich Campus-Week 12 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
VBA & Excel Barry L. Nelson IEMS 465 Fall Quarter 2003.
Muffin Shop - if, calculations etc. (muffins, muffins2) Please use speaker notes for additional information!
Introduction to Class Modules Please use speaker notes for additional information!
Tutorial 7: Sub and Function Procedures1 Tutorial 7 Sub and Function Procedures.
Programming with Microsoft Visual Basic 2012 Chapter 7: Sub and Function Procedures.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 11 1 Microsoft Office Access 2003 Tutorial 11 – Using and Writing Visual Basic for Applications.
Multiple Forms and Standard Modules
Why to Create a Procedure
InvEasy (Project1) Please use speaker notes for additional information!
Break Processing Please use speaker notes for additional information!
Copyright © 2001 by Wiley. All rights reserved. Chapter 5: The Repetition Process in Visual Basic Event Driven Loops Determinate Loops Indeterminate Loops.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
110-G1 Motivation: Within a program, may have to perform the same computation over and over Many programs share the same computation (e.g. sorting) To.
Input Textboxes Input Boxes Different than textboxes Good for small amount of input (form full of textboxes is not nice) X = Inputbox(“prompt message”,
New Project in Visual Basic Please use speaker notes for additional information!
1 Flow Control II Code: Select-Case and For-Next Controls: Frames and OptionButtons.
Visual Basic Programming Making Decisions: Loops & Decision Structures ©Copyright by Ronald P. Kessler, Ph.D.
MDI with Menu Please use speaker notes for additional information!
Random Files Please see speaker notes for additional information!
CS285 Visual Basic 2 Department of Computing UniS 1 Statements in Visual Basic A statement is the fundamental syntactical element of a program smallest.
CIS 338: Classes and Modules Dr. Ralph D. Westfall May, 2011.
Chapter 16: Programming Structures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Delivery and other DO Examples Please use speaker notes for additional information!
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
Chapter 16: Programming Structures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
CS 101 Test 2 Study Guide Acronyms RAD - Rapid Application Development IDE - Integrated Development Environment GUI - Graphical User Interface VB - Visual.
Two Forms Please use speaker notes for additional information!
1 CS105 Discussion 5 – Variables and If Announcements MP 1 due on Monday Midterm 1 on Tuesday If you need a conflict, request it NOW!!
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Pay Example (PFirst98) Please use speaker notes for additional information!
Debugging, Static Variables, ByRef, ByValue Chapt. 6 in Deitel, Deitel and Nieto.
Visual Basic I/O Programs (ProjRead1, ProjRead2, ProjWrite1, ProjPay) Please use speaker notes for additional information!
Maximum Profit Please use speaker notes for additional information!
31/01/ Selection If selection construct.
110 E-1 Variables, Constants and Calculations(2) Chapter 3: Operations on variables, scope of a variable, formatting data Doing Arithmetic.
Using a Database Access97 Please use speaker notes for additional information!
Chapter 13 Copyright 2000 All rights reserved 1 Chapter 13 Object-Oriented Programming.
Knowledge Base. Defining a Variable Dim statement Dim intXX As Integer Public in a Module Public dblNN As Double.
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
‘Tirgul’ # 5 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #5.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
Functions CMSC 201 – Lab 5. Overview Objectives for today's lab:  Practice breaking down a program into multiple functions  Practice writing function.
Multiple forms - SDI & MDI Please use speaker notes for additional information!
Computer Science Up Down Controls, Decisions and Random Numbers.
Visual Basic - Break Processing
Visual Basic Fundamental Concepts
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Active X EXE (Out of Process Components)
CSI 101 Elements of Computing – Spring 2009
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Object-Oriented Programming: Classes and Objects
Visual Basic..
Department Array in Visual Basic
CIS16 Application Development and Programming using Visual Basic.net
Please use speaker notes for additional information!
Visual Basic Programming
Please see speaker notes for additional information!
Presentation transcript:

Savings Account using Class Modules Please use speaker notes for additional information!

Enter 100 in Transaction Amount and Click Deposit. Click on reset to transfer into balance. Enter amount and click on withdrawal. Click on reset to make opening balance.

SavAcct.vbp The deposit and withdrawal methods give the class the behaviors it needs to increase or decrease the balance. vTranAmt is the information passed to the deposit or withdrawal method. The Get and Let procedures are assign and retrieve property values. In this example, I do not want to assign to Balance so there is no Let.

SavAcct.vbp objSavAcct is dimensioned objSavAcct is instantiated Reset puts the current objSavAcct.Balance on the form using Get. The Deposit method receives wkTranAmt as vTranAmt and curBalance is changed. When I get the Balance it receives curBalance. “Occurs before the focus shifts to a (second) control that has its CausesValidation property set to True.” from Microsoft VB In fact, I am not really doing validation here, I am assigning.

SavAcct00.vbp

On the form an InputBox is used to take in the interest rate. The interest rate is now assigned to objSavAcct.IntRate where as vIntRate it is assigned to intIntRate.

SavAcct00.vbp

Private Sub cmdDpsit_Click() objSavAcct.Deposit wkTranAmt lblClsBal.Caption = objSavAcct.Balance cmdDpsit.Enabled = False cmdWthDrwl.Enabled = False cmdSetInt.Enabled = False cmdReset.Enabled = True End Sub Private Sub cmdDpsit_Click() objSavAcct.Deposit (wkTranAmt) lblClsBal.Caption = objSavAcct.Balance cmdDpsit.Enabled = False cmdWthDrwl.Enabled = False cmdSetInt.Enabled = False cmdReset.Enabled = True End Sub Both ways of coding work: The steps in coding the line objSavAcct.Deposit (wkTranAmt) The Deposit Method on the Class Module SavAcct.

SavAcct00.vbp In this example the validate makes sure that an amount was entered in the transaction box. However, problems develop if the entry is not made because the amount from the last transaction is used. A simple fix is shown below. Private Sub txtTrnAmt_Validate(Cancel As Boolean) If txtTrnAmt.Text <> "" Then wkTranAmt = txtTrnAmt.Text Else wkTranAmt = 0 End If End Sub

SavAcct01.vbp

RaiseEvent on insufficient funds.

SavAcct01.vbp If there are events that can be raised or triggered, the Dim statement needs to include the WithEvents clause.

SavAcct01.vbp Note that the code that puts out the msgbox saying insufficient funds is on the form. In this example, the validate checks to make sure a transaction amount was entered before transferring to wkTranAmt, and acts on the problem by setting to 0.

SavAcct01.vbp

SavAcct02.vbp

Public Sub Add(ByVal vAcctNbr As String, ByVal vIntRate As Integer) Dim NewSavAcct As New SavAcct With NewSavAcct.AccountNumber = vAcctNbr.IntRate = vIntRate colSavAccts.Add NewSavAcct,.AccountNumber End With 'The last line of the with block actually adds the NewSavAcct object to the savings 'accounts collection (SavAccts) and uses the AccountNumber as a key to the 'collection. You can retrieve that object from the collection by using the 'AccountNumber. End Sub Public Sub Remove(ByVal vAcctNbr As String) colSavAccts.Remove vAcctNbr End Sub Option Explicit 'A collection is a container object - it contains objects 'A collection can only have certain methods such as Add, Remove and Item Private colSavAccts As Collection Private Sub Class_Initialize() Set colSavAccts = New Collection End Sub This sets up a NewSavAcct which is an object of the SavAcct type and then adds it to the collection.

SavAcct02.vbp Public Function Item(ByVal vAcctNbr As String) As SavAcct Set Item = colSavAccts.Item(vAcctNbr) End Function 'Retrieves a particular object from the collection - this is the item method Option Explicit 'A collection is a container object - it contains objects 'A collection can only have certain methods such as Add, Remove and Item Private colSavAccts As Collection Private Sub Class_Initialize() Set colSavAccts = New Collection End Sub

SavAcct02.vbp Public Function NewEnum() Set NewEnum = colSavAccts.[_NewEnum] End Function

SavAcct02.vbp

Private Sub Form_Load() Set objSavAcct = New SavAcct Set colSavAccts = New SavAccts Call Initialize_Variables End Sub Public Sub Initialize_Variables() wkAcctNbr = "" wkBalance = 0 wkIntRate = 0 wkTranAmt = 0 txtAcctNbr.Text = "" lblOpnBal.Caption = "" lblClsBal.Caption = "" txtIntRate.Locked = False txtIntRate.Text = "" txtIntRate.Locked = True txtTrnAmt.Text = "" cmdDpsit.Enabled = True cmdWthDrwl.Enabled = True cmdReset.Enabled = True End Sub Instantiates the class modules SavAcct and SavAccts.

SavAcct02.vbp Private Sub txtIntRate_LostFocus() With txtIntRate.Appearance = 0.BackColor = &H F.BorderStyle = 0.Locked = True wkIntRate =.Text End With End Sub Private Sub cmdSetInt_Click() With txtIntRate.Appearance = 1.BackColor = &H BorderStyle = 1.Locked = False.SetFocus End With End Sub