Presentation is loading. Please wait.

Presentation is loading. Please wait.

SYSTEMSDESIGNANALYSIS 1 OO: Chapter 9 Visual Basic: Building Components Jerry Post Copyright © 1999.

Similar presentations


Presentation on theme: "SYSTEMSDESIGNANALYSIS 1 OO: Chapter 9 Visual Basic: Building Components Jerry Post Copyright © 1999."— Presentation transcript:

1 SYSTEMSDESIGNANALYSIS 1 OO: Chapter 9 Visual Basic: Building Components Jerry Post Copyright © 1999

2 SYSTEMSDESIGN 2 Components  A reusable class installed on Windows  Can be used in any standard programming system:  Visual Basic  C++  Internet Information Server  Excel, Access, …  Class properties or attributes  Class methods or functions

3 SYSTEMSDESIGN 3 Creating a Component in VB  Start Visual Basic (might not exist on student version)  File | New Project: Active X DLL  Project | Properties  Name, Description  Class Module  Properties: Name  Warning: Pick simple, informative names!

4 SYSTEMSDESIGN 4 VB Component Properties  Code: Create Variables to Hold Properties  Option Explicit (catches typos by requiring all variables to be pre- defined)  Declare property variables: Private m_InterestRate As Double Private m_Years As Integer Private m_FutureValue As Currency Private m_PresentValue As Currency  Tools | Add Procedure  Name  Property check box  Public

5 SYSTEMSDESIGN 5 VB Property Code Option Explicit Private m_InterestRate Public Property Get InterestRate() As Variant InterestRate = m_InterestRate End Property Public Property Let InterestRate(ByVal vNewValue As Variant) m_InterestRate = vNewValue End Property Retrieve a property value from the object and give it to caller. Accept a property value, test it, and store it in the object.

6 SYSTEMSDESIGN 6 VB Methods (Function or Sub)  Tools | Add Procedure  Name  Property check box  Public  Write code  Use property variables  Assign property variables Public Sub NPV() m_PresentValue = m_FutureValue / (1 + m_InterestRate) ^ m_Years End Sub

7 SYSTEMSDESIGN 7 VB Testing and Building Components  Save the project: File | Save  Add a new project (for testing)  File | Add Project: Standard EXE  Make the Component visible  Project | References  Create a form for the user  Add input boxes, and a command button (or other event)  Code to activate and use the component Private Sub cmdCompute_Click() Dim obj As Compute Set obj = CreateObject("SimpleFinance.Compute") obj.FutureValue = txtFuture obj.InterestRate = txtInterestRate obj.Years = txtYears obj.NPV txt.PresentValue = obj.PresentValue End Sub

8 SYSTEMSDESIGN 8 Finalizing VB Components  Add error handling and return messages/flags.  Test it extensively.  Build the DLL: File | Make ….dll  Distribute the DLL and the applications.  Register the DLL: regsvr32 SimpleFinance.dll  To remove it: regsvr32 /u SimpleFinance.dll


Download ppt "SYSTEMSDESIGNANALYSIS 1 OO: Chapter 9 Visual Basic: Building Components Jerry Post Copyright © 1999."

Similar presentations


Ads by Google