Presentation is loading. Please wait.

Presentation is loading. Please wait.

instance variables property procedures for the mintQuantity instance variable.

Similar presentations


Presentation on theme: "instance variables property procedures for the mintQuantity instance variable."— Presentation transcript:

1

2 instance variables property procedures for the mintQuantity instance variable

3 Accessing the Values of a Class The Property Get procedure retrieves a property from a class, making it available to the outside world. The Property Let procedure assigns a value from the outside world to a property of the class. Property Let and Property Get are the only way to assign and retrieve property values for a class. Otherwise, there is no other “doorway” through which they can pass.

4 Class Module Code

5 Form Code

6 Creating a New Object Using a Class Creating a class module defines a new class Code that creates and uses objects is placed in form and code modules, whereas a class must be placed in a class module Create an object of a class with the New keyword—called instantiating an object The New keyword creates a new instance of a class when the object is first used

7 Dimensioning objects with the New keyword: – Dim EmployeeAs New cEmployee – Private mInventoryAs New Cinventory Next, create a form that instantiates an object of the class CProduct

8 Using a For Each… Next Loop Private Sub cmdExit_Click() ‘this procedure will unload all forms that are currently loaded ‘in the project Dim OneForm As Form For Each OneForm in Forms Unload OneForm Next End This is a very useful piece of code for quitting a project

9 Disabling Controls using a For Each…Next Loop Dim AnyControl As Control For Each AnyControl in frmMain.Controls AnyControl.Enabled = False Next Uses the controls collection to change a property of multiple controls

10 10 Example of Inheritance in VB.NET Examine 1st line of code for a form in the Editor (look at Visual Studio 2005 in the labs) Public Class Form1 Inherits System.Windows.Forms.Form Inherited Class, Derived Class Subclass, Child Class Base Class, Superclass, Parent Class

11 Hello World in VB.NET

12 Collections A Collection Class holds references for a series of objects created from the same class or from different classes Actually a collection holds references to the objects – You reference by Index Number or a Key – Similar to list box and the associated items in the list box

13 Key for Collection Objects Key must be a string Can be used to reference individual objects in the collection Declare the Key as String at the module level of the Class module for the object (not the collection) Add Property Get and Let procedures

14 Create a collection by writing a new class module and then declaring an object variable (to create an object). Each object in the collection is known as an item. Each object has a position known as its index. A collection is declared with a Dim, Public, or Static statement just like any other object variable: Dim mProducts As New Collection VB always updates the Count property of a collection every time you add or remove an item from a collection. Collections

15 The Add method adds an item to the collection. mProducts.Add Prod1 The Remove method removes an item according to its index in the collection. mProducts.Remove 2 It is best to provide a unique key to each object in a collection, rather than rely upon an index (see remove example above). It is difficult to associate an index with a particular product. Using a key value makes locating an object much easier. Add a string in the CProduct class: Private mstrProductCode As String Use the string to add an object to a collection or remove it from a collection Collections

16 Using a Collection in a Form


Download ppt "instance variables property procedures for the mintQuantity instance variable."

Similar presentations


Ads by Google