User Defined Types, Collections, Enumerations & Classes CIS 338 Tony Lopez (a Cal Poly student) updated April 2003.

Slides:



Advertisements
Similar presentations
Integrated Business Applications with Databases (D3) Jenny Pedler
Advertisements

Sub and Function Procedures
VBA Modules, Functions, Variables, and Constants
instance variables property procedures for the mintQuantity instance variable.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
Creating Object Oriented Programs Object oriented (OO) terminology Class vs. object Instantiate an object in a project Understand Class_Initialize / Terminate.
CSI 101 Elements of Computing Spring 2009 Lecture # 14 – Classes and Objects Wednesday, April 15th, 2009 and Monday, April 20th, 2009.
© The McGraw-Hill Companies, 2006 Chapter 7 Implementing classes.
VBA & Excel Barry L. Nelson IEMS 465 Fall Quarter 2003.
Object Oriented Software Development
CS0004: Introduction to Programming Variables – Numbers.
Why to Create a Procedure
Chapter 10: Writing Class Definitions Visual Basic.NET Programming: From Problem Analysis to Program Design.
CSCI 3327 Visual Basic Chapter 6: Methods: A Deeper Look UTPA – Fall 2011.
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
PROGRAMMING Functions. Objectives Understand the importance of modular programming. Know the role of functions within programming. Use functions within.
Microsoft Access Using Visual Basic Routines. Visual Basic Datatypes Boolean Byte Currency Date Double Integer Long Object Single String Variant Hyperlink.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
© 2012 EMC Publishing, LLC Slide 1 Chapter 8 Arrays  Can store many of the same type of data together.  Allows a collection of related values to be stored.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
C# D1 CSC 298 Elements of C# code (part 2). C# D2 Writing a class (or a struct)  Similarly to Java or C++  Fields: to hold the class data  Methods:
SYSTEMSDESIGNANALYSIS 1 OO: Chapter 9 Visual Basic: Building Components Jerry Post Copyright © 1999.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
Tutorial 6 The Repetition Structure
CIS 338: Classes and Modules Dr. Ralph D. Westfall May, 2011.
10-Nov-15 Java Object Oriented Programming What is it?
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA ‏ Visibility Control.
Applications Development
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
1 Working with Objects. 2 Defining a Class in VB.NET A class is a user-defined data type You can declare it as part of a module, but usually in a separate.
6c – Function Procedures Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
1 Working with Data Structures Kashef Mughal. 2 Chapter 5  Please review on your own  A few terms .NET Framework - programming model  CLR (Common.
Copyright © 2012 Pearson Education, Inc. Chapter 11: Structured Data.
Overview The Basics – Python classes and objects Procedural vs OO Programming Entity modelling Operations / methods Program flow OOP Concepts and user-defined.
Java Class Structure. Class Structure package declaration import statements class declaration class (static) variable declarations* instance variable.
JAVA PROGRAMMING PART III. METHOD STATEMENT Form of method statement [ ] [static] ( [ ]) { } Example public static void main(String args[])
CompMathBSc, English 5 October 2006 Programming basics — continued  Arrays  Cycle Statements: Loops  Control Structures vs Conditions  Subs: Procedures.
Created by Alia Al-Abdulkarim 2008 Visual Basic Vs. Java.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
CIS 338: VB Variables Dr. Ralph D. Westfall April, 2011.
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
Class Fundamentals BCIS 3680 Enterprise Programming.
Object-Oriented Programming: Classes and Objects Chapter 1 1.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
Chapter 9 Introduction to Arrays Fundamentals of Java.
‘Tirgul’ # 5 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #5.
Basic Class Structure. Class vs. Object class - a template for building an object –defines the instance data that the object will hold –defines instance.
Introduction to Enumerations CMSC 202. Enumerated Values Enumerated values are used to represent a set of named values. Historically in Java (and other.
Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #5
C# for C++ Programmers 1.
VBA - Excel VBA is Visual Basic for Applications
Object-Oriented Programming: Classes and Objects
Method.
Creating Your OwnClasses
Anatomy of a class Part I
Object-Oriented Programming: Classes and Objects
Using local variable without initialization is an error.
11/10/2018.
CIS16 Application Development and Programming using Visual Basic.net
The Object-Oriented Thought Process Chapter 04
CS2011 Introduction to Programming I Objects and Classes
CSCI 3327 Visual Basic Chapter 6: Methods: A Deeper Look
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
Tonga Institute of Higher Education
Object-Oriented Programming
Java Programming Language
Introduction to VB programming
ITE “A” GROUP 2 ENCAPSULATION.
Encapsulation.
Anatomy of a class Part I
Presentation transcript:

User Defined Types, Collections, Enumerations & Classes CIS 338 Tony Lopez (a Cal Poly student) updated April 2003

User Defined Types  Integer, String, Double, etc.  Use the ‘Let’ keyword in assignment  Can be passed as parameter to a Function or Procedure  Can be a return value of a function  Cannot be passed ByVal  Like C++ Structures

Creating User Defined Types  Must be created in a Module (struct)  Can use Enumerations, or other User Defined Types e.g., Public Type Student ID As String Name As String Major As Majors End Type

Using User Defined Types  Declare same as other data types Dim newStudent As Student newStudent.ID = " " newStudent.Name = "Jenny" newStudent.Major = Majors.CIS [Enumeration]

Get, Let, Set Review  Get – only used in Property Functions when user gets a value from the class  Let – used to assign values  Dim nIndex as Integer  Let nIndex = 0 (optional; could use following instead)  nIndex = 0  Set – used to assign Objects (required)  Dim colNames as Collection  Set colNames = New Collection

Accessing Private Variables  Java – getters and setters public void setName(String someName) { name = someName; } public String getName () { return name; // name declared above }

Accessing Private Variables  Visual Basic – Property Get, Let, Set Public Property Let Name(ByVal nuName As String) sName = nuName 'sName declared in this Sub End Property Public Property Get Name() As String Name = sName End Property Public Property Set MyObj(ByVal nuMyObject As Object) objMyObject = nuMyObj End Property

Properties  Allows for the familiar dot operator  sStudentName = objStudent.Name ‘ =GET  Let objStudent.Name = “Jenny”  Set objStudent.MyObject = objObject  Doesn’t violate encapsulation  Allows for code to be run in the Property Get, Let, Set functions

Collections  Collection – a group of items that is itself a type of object (p. 373)  Can be passed to and from Functions  Use New when declaring  Use Set when assigning  Forms, Controls collections (collect)  User Defined Collections (usercollect)

Collections Properties and Methods  Common to all Collections  Count property  Item method  Common to Most Collections  Add  Remove  Special collections may have other methods

User Defined Collections  Property and Methods  Count property  Item method  Add method  Remove method

User-Defined Collections  Dim col[Name] As New Collection  Loop through collection (usercollect)  For Each [type variable] In col[Name]  ‘ do something with [type variable]  Next [type variable]  For Each.. Next must use Variants or Objects (objcollect)  Use Variant for Strings

Enumerations  Allows you to define a group of constants as a data type (p. 372) ‘ Enumeration Declaration Public Enum Majors(types) ACC = 0 CIS = 1 EBZ = 2 FRL = 3 IB = 4 MKT = 5 MHR = 6 TOM = 7 End Enum

Enumerations  Works with integers  String constants won’t work  ACC = “Accounting” NG, must use ACC=0  Using the enum: Dim myMajor As Major myMajor = CIS ‘ or myMajor = Major.CIS (stored as CIS=1)

Classes  Use Class Module  Create instances of the class using the New keyword  Dim objStudent as New clsStudent  Combine attributes (Properties) and methods (Sub Procedures and Functions) into one object  Similar to classes in Java  Can be placed in Collections