Constructors. You got plenty of experience using constructors in the Marching Band program. A constructor is the subroutine which creates objects from.

Slides:



Advertisements
Similar presentations
Working with Intrinsic Controls and ActiveX Controls
Advertisements

Lecture Set 4 Data Types and Variables Part B – Variables, Constants, Expressions Conversion Rules Options Strict, Option Explicit Scope of Definition.
Pemrograman VisualMinggu …3… Page 1 MINGGU Ke Tiga Pemrograman Visual Pokok Bahasan: Class, Objects, Methods and Instance Variable Tujuan Instruksional.
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
Java Inheritance. What is inherited A subclass inherits variables and methods from its superclass and all of its ancestors. The subclass can use these.
 Option 1 › Separate entries and hide fields › Hide columns or use separate spreadsheets  Option 2 › Build them up in pieces › Use parentheses if you.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
C++ data types. Structs vs. Classes C++ Classes.
More on Operator Overloading CS-2303, C-Term More on Operator Overloading CS-2303 System Programming Concepts (Slides include materials from The.
Graphics Procedure (IDrawable) 1. Basic Procedure For Drawing ThingsToDraw Create Objects From Classes Add Them to PictureBox Use the Paint Event to draw.
1 Flash Actionscript Actionscript and Objects. 2 Actionscript and Objects ActionScript is what's known as an object-oriented programming language. Object-oriented.
Modules Standard Modules. Standard Modules The Subs and Functions worked perfectly well where they were – inside the two lines “Public Class Form1” and.
1/26/2004 PPCC - Introduction to VB6 Copyright ©2004, Tore Bostrup 1 Introduction to VB6 Materials & Prerequisites Course Outline Background Information.
Graphics Object. Group Activity! In each group, pull out one piece of blank paper and one pen or pencil Start with the piece of paper on the left side.
Adding Controls to User Forms. Adding Controls A user form isn’t much use without some controls We’re going to add controls and write code for them Note.
Apply Sub Procedures/Methods and User Defined Functions
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Seven Sub and Function Procedures.
Classes and Class Libraries Examples and Hints November 9,
Creating Embedded Formative Assessment Dr. Steve Broskoske Misericordia University EDU 533 Computer-based Education.
VBA session 3 Paul Rubinov  My job: diverse audience so Bore you for 15 minutes. Confuse you for the other 15 min.  Feel free to contact me
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Ch 11: Userforms CP212 Winter Topics Designing User Forms o Controls Setting Properties o Tab Order o Testing Writing Event Handlers o Userform_Initialize.
1 Visual Basic for Applications (VBA) for Excel Prof. Yitzchak Rosenthal.
® Microsoft Access 2010 Tutorial 11 Using and Writing Visual Basic for Applications Code.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Multiple Forms, Container Controls, AddHandler This presentation is based on the Forms and ContainerControls VB Projects 1.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Microsoft Office Excel Copyright © 2008 Pearson Prentice Hall. All rights reserved
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
Using Visual Basic for Applications (VBA) – Project 8.
‘Tirgul’ # 7 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #7.
BİL528 – Bilgisayar Programlama II Making Decisions, Loops, Debugging, Designing Objects Using Classes 1.
Introduction to the Windows API n API - Application Programming Interface n an API is the software interface for things such as the OS n an API is the.
Chapter 9: Writing Procedures Visual Basic.NET Programming: From Problem Analysis to Program Design.
Introduction to Exception Handling and Defensive Programming.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
ECE122 Feb. 22, Any question on Vehicle sample code?
Chapter 16: Programming Structures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Applications Development
Visual C# 2012 for Programmers © by Pearson Education, Inc. All Rights Reserved.
Programming with Microsoft Visual Basic 2012 Chapter 11: Classes and Objects.
ASNApalooza 2007 © Copyright 2007 by ASNA. All rights reserved. by Mike Marlowe ASNA Instructor/Pre-Sales Engineer © Copyright 2007 by ASNA. All rights.
ME 142 Engineering Computation I Using Subroutines Effectively.
# 1# 1 Using Procedures and Functions What is a procedure? What is a sub procedure (subroutine)? Built-in functions in your code What is a function? CS.
Controls and Events. The Next Step In the first module, we discussed general problem solving In this module, we’ll apply what we learned, from specification.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
1 Chapter 3 – Examples The examples from chapter 3, combining the data types, variables, expressions, assignments, functions and methods with Windows controls.
Procedures Subs and Functions. Procedures Before OOP, subroutines were the primary high-level way to organize a program. In OOP, this role has been taken.
ME 142 Engineering Computation I Using Subroutines Effectively.
110 E-1 Variables, Constants and Calculations(2) Chapter 3: Operations on variables, scope of a variable, formatting data Doing Arithmetic.
Variables and Strings. Variables  When we are writing programs, we will frequently have to remember a value for later use  We will want to give this.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
1 Introduction to Object Oriented Programming Chapter 10.
COMPREHENSIVE Access Tutorial 11 Using and Writing Visual Basic for Applications Code.
Copyright © Curt Hill Simple I/O Input and Output using the System and Scanner Objects.
ILM Proprietary and Confidential -
Java I/O Basics MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation ©Akhilesh Bajaj,
VB.NET and Excel VB.NET allows you to write code to manipulate Excel. You can create, open, and save Excel files. You can read data from Excel. You can.
PaintPictureBoxDemo Refers to the PaintPictureBoxDemo Visual Basic Program Included With The Lecture.
Defining Data Types in C++ Part 2: classes. Quick review of OOP Object: combination of: –data structures (describe object attributes) –functions (describe.
© 2016, Mike Murach & Associates, Inc.
Microsoft Visual Basic 2005: Reloaded Second Edition
IFS410: Advanced Analysis and Design
Java Inheritance.
CIS16 Application Development and Programming using Visual Basic.net
Methods.
Classes & Objects A deeper Look Chapter 10 & 11
Java Programming Language
C++ data types.
Presentation transcript:

Constructors

You got plenty of experience using constructors in the Marching Band program. A constructor is the subroutine which creates objects from a class. Every class has a default constructor which takes no parameters– New(). This default constructor is there even if you don’t see it. 2

ThreeDPoint In the class definition, there is no Sub New. However, I can still call the default constructor like this: 3

Creating a Constructor However, we can create our own constructor. There are two main reasons for creating your own constructor: 1.To initialize the value of variables using parameters; and 2.To create any objects that the current object will need; that is, calling constructors of other classes. Here’s the Rank class’s constructor from Marching Band: Notice that it Initializes the mStepSize variable; Creates the 10 members of the rank by calling BandMember’s constructor. 4

Creating a Constructor Here’s a simple constructor for the ThreeDPoint class. It simply initializes the variables. 5

Constructors in Action To understand how to declare variables and create objects using constructors, View the ConstructorsInAction video. 6

Overloads VB allows functions and subs (including constructors) to be overloaded. This means that you can have two or more procedures with the same name. They just have to differ in the number and/or type of parameters. Overloads are used widely in the built-in VB.NET classes (you’ll see many in the graphics routines), but you can create your own overloads as well. 7

Overload Example 8

ToString Older versions of VB, including Visual Basic for Applications in Excel, do not have a “ToString” function. VBA is a loosely-typed language that does all sorts of datatype conversions in the background for you (sometimes well, sometimes not). VB.NET, the descendant of VBA (VB 6), is a strongly typed language, which means that functions, subs and properties can require a particular parameter type. If a String parameter type is required you can put ToString on the end of a variable or expression to convert it to a string. 9

ToString For example: Notice that when I try to put a numeric value into a Text property, I get an error: ToString is the cure: (Note: I added the extra blank lines so the error message wouldn’t cover up the line above. This doesn’t mean that I now approve of lots of blank lines!) 10

ToString The standard datatypes (even String) have built-in ToString methods. ToString can even be applies to expressions: However, the classes that you create will have a default ToString method that’s pretty useless: It just displays the name of the class. And this can be annoying when you start adding objects of your own classes to ListBoxes and ComboBoxes! 11

Using ToString to Format Numbers ToString can be used to format numbers, like this: 12