1 / 9

Creating & Using Objects

CTEC2902 Advanced Programming. Creating & Using Objects. CTEC2902 Advanced Programming. The Story So Far You have been… Doing review exercises in labs & elsewhere Revising year 1 material (essential) Let us carry on…. What is an Object?. Any thing you can define and

Download Presentation

Creating & Using Objects

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. CTEC2902Advanced Programming Creating & Using Objects

  2. CTEC2902Advanced Programming • The Story So Far • You have been… • Doing review exercises in labs & elsewhere • Revising year 1 material (essential) • Let us carry on…

  3. What is an Object? Any thing you can define and interact with in your program To create objects … Dim object_name As New class_name e.g., Dim dtSales As New DataTable You can now use dtSales to process data, using all features of DataTable

  4. Creating & Using Objects Question: What service does a class provide? How do I create instances of the class? What are its properties and methods? How can I use its services? Answer: you need to read the API of the class

  5. clsPerson Class Exercises • Create 3 objects, named Zoe, Jay, and Joe • Dim Zoe As New clsPerson • Dim Jay As New clsPerson • Dim Joe As New clsPerson

  6. Properties To refer to a property Object.property_name Remember: properties behave like variables So, set or get values • e.g. to set values • Zoe.FirstName = “Zoe” • Zoe.Surname = “Smith” • Jay.DoB = #01/04/1995# • Joe.Gender = “M” e.g. to get values txtName.Text = Zoe.Surname lblBirthDate.Text = Zoe.Dob e.g. also … Zoe.DoB = Jay.DoB Joe.Gender = Jay.Gender

  7. Methods Remember: methods behave like functions So, consider parameters To refer to a method Object.method_name() • e.g. Show Zoe’s age on screen • lblAge.Text = Zoe.Age() • txtName.Text = Jay.FullName()

  8. Essential Revision • In your own time ... • Review these slides • Make sure you understand properties and methods

  9. More on objects next week

More Related