ADV_GISVB - IV1 Advanced GIS Objects/Interfaces Week 5 2008 Spring.

Slides:



Advertisements
Similar presentations
Lists, Loops, Validation, and More
Advertisements

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 1 STARTING OUT WITH Visual Basic 2008 FOURTH EDITION Tony Gaddis.
Week 10.  Protecting Code  Protecting Worksheets  Error Handling  Charts.
Using Macros and Visual Basic for Applications (VBA) with Excel
30/04/ Selection Nested If structures & Complex Multiple Conditions.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Tutorial 12: Enhancing Excel with Visual Basic for Applications
OOP-Creating Object-Oriented Programs
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7- 1.
Creating Object Oriented Programs Object oriented (OO) terminology Class vs. object Instantiate an object in a project Understand Class_Initialize / Terminate.
1 Prototyping for HCI Spring 2004 (Week 8) Jorge A. Toro.
VB Classes ISYS 573. Object-Oriented Concepts Abstraction: –To create a model of an object, for the purpose of determining the characteristics (properties)
Visual Basic: An Object Oriented Approach 4: Simple Programming in VB.
Scope of Variables and Constants A Variable or Constant may exist and be Visible for an entire project, for only one form, or for only one procedure Therefore,
Chapter 12: Advanced Topics: Exception Handling Visual Basic.NET Programming: From Problem Analysis to Program Design.
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.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
A First Program Using C#
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Adv_GISArcObjects - 11 VBA and ArcObjects Fall 2003 Advanced GIS.
Automating Tasks with Visual Basic. Introduction  When can’t find a readymade macro action that does the job you want, you can use Visual Basic code.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Multiple Forms, Standard Modules, And Menus
1 Visual Basic for Applications (VBA) for Excel Prof. Yitzchak Rosenthal.
Chapter 6 Understanding the Structure of an Application: Procedures, Modules, and Classes.
Adv_GISArcObjects - 11 VBA and ArcObjects Programming Week 1 Spring 2008 Advanced GIS.
Why to Create a Procedure
Chapter 9: Getting Comfortable with Object- Oriented Programming.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
Copyright © 2001 by Wiley. All rights reserved. Chapter 2: Using Visual Basic to Create a First Project Getting Started with VB Development Environment.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Chapter 12 Making Tools Week 7 Fall Tools (events) besides Click MouseDown, MouseUp, MouseMove CursorID defines mouse appearance Eabled to disable.
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
Chapter Two Creating a First Project in Visual Basic.
CIS 338: Classes and Modules Dr. Ralph D. Westfall May, 2011.
Applications Development
It’s time to write and send your first message using the new Outlook. In a new message, first get oriented to the Ribbon. The Message tab is on.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Class Builder Tutorial Presented By- Amit Singh & Sylendra Prasad.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
COPYRIGHT 2010: Dr. David Scanlan, CSUS OBJECTIVES: How to write classes How to create an object from a class using the "New" keyword. How to communicate.
Chapter 11 Navigating Object Model Diagrams Week 6, 2008 Spring.
31/01/ Selection If selection construct.
Slide 1 Controls v Control naming convention –Label: lblName –Command Button: cmdName –Text Box: txtName.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
Tutorial 81 Field, Record, Data File Field - a single item of information about a person, place, or thing Record - a group of related fields that contain.
Chapter 13 Copyright 2000 All rights reserved 1 Chapter 13 Object-Oriented Programming.
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
Using Forms and Form Elements In Visual Basic.NET.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
Chapter 7 Multiple Forms, Modules, and Menus. Section 7.2 MODULES A module contains code—declarations and procedures—that are used by other files in a.
COMPREHENSIVE Excel Tutorial 12 Expanding Excel with Visual Basic for Applications.
Apply Procedures to Develop Message, Input, and Dialog Boxes
3.01 Apply Controls Associated With Visual Studio Form
File Handling.
Introduction to VB6 Week 1 3/2/2004 PPCC - Introduction to VB6
3.01 Apply Controls Associated With Visual Studio Form
Exploring Microsoft Office Access 2007
Lecture 3 Introducing ArcObjects
Lecture 4 An example for changing a layer’s Name
CIS16 Application Development and Programming using Visual Basic.net
CS285 Introduction - Visual Basic
Please use speaker notes for additional information!
Constructors, GUI’s(Using Swing) and ActionListner
Introduction to Programming
Chapter 8 - Functions and Functionality
Presentation transcript:

ADV_GISVB - IV1 Advanced GIS Objects/Interfaces Week Spring

ADV_GIS2 Objects - create your own The object templates is called class modules Object is an instance of a class  There are tangible objects, such as control on a form and intangible objects - used in a code, like a collection object. A class defines properties, methods, events for all the objects created from that class.  Instances from same class have same set of properties but different values Object variable is only a pointer.  Such as Map Class in ArcMap/ArcView. One map object points to world map with small scale and another points to Tennessee with larger scale and different projection.

ADV_GIS3 Object Variables Refer an object variable to existing tangible object use “Set” keyword.  Set lstMyListBox = frmMain.lstSlides For Intangible Objects, object variables act as the “handles” for reaching the objects. To create an intangible object, declare a variable as the object class, then set this variable as New instance of the class. Dim MyCollection As Collection Set MyCollection = New Collection ‘point to new instance Dim YourCollection As Collectioin Set YourCollection = MyCollection ‘point to existing object variable Set MyCollection = Nothing ‘release an object variable from pointing to an object

ADV_GIS4 Generic and specific object types Object, Form and Control are generic object type. Specific forms and types of controls are called specific object types. The Object class is the most generic, with two subclasses, Form and Control (frmMain, txtMyText) You can create instances from any form in the project.- Create a new project with cmdCreate Private Sub cmdCreate_Click() Dim frmNew As frmMain Set frmNew = New frmMain frmNew.show End Sub ‘click cmdCreate 3 times, you will create 3 identical forms

ADV_GIS5 ArcObjects Diagram

ADV_GIS6 Keyword “New” Dim X As New Collection ‘ one-step approach, slow Dim X As Collection ‘two-step approach, better Set X = New Collection Generic objects and controls can not be created with the New keyword Set X = New Object Set X = New Form Set X = ListBox Set X = New TextBox Set X = New ListBox Set X = New txtTitle Set X = New lstSlides Dim X As Control Dim Y As Control Set X = frmMain.lstSlides Set Y = X This is ok!

ADV_GIS7 Class – general structure Public Class ClassName ‘Properties definitions go here ‘Property Get/Set statements go here ‘Methods go here End Class

ADV_GIS8 Class Property Default value for title (if a property has a default value) type in code in Class_Initialize() procedure Private Sub Class_Initialize() mvarTitle = “Default Title” End Sub To create a read-only property, you don’t need to supply the Property Let procedure. For write-only property, no need for Get procedure Read-only procedure: e.g. Count property of a class Write-only property: user change password but doesn’t show existing password

ADV_GIS9 Create a Class Project > Add Class Module. The name of the class module is the name of the class to be created. Class module is saved as.cls files. A.cls file can be added to any VB project, where instances of the class can be created. You may rename it as “DVD” Create a Title property for DVD Type in codes as in the box mvarTitle is used to store the property value within the class module Suppose you have a class named DVD, and an instance named aDVD, then create a form to set title of DVD to whatever user’s inputbox provides, and then show it to the txtDVD box. Option Explicit 'General Declaration section Private mvarTitle As String 'Write property Public Property Let Title(NewTitle As String) mvarTitle = NewTitle End Property 'Read property Public Property Get Title() As String Title = mvarTitle End Property

ADV_GIS10 Create class DVD with properties and methods In “Insert | Class Module” you will have chance to insert a class to your project. Type in the codes from previous slide Add a method “PlayMusic” with variable receiving value from calling sub. Then the value would be determined by Case 1,2,3,4 and its corresponding music type will be shown using msgbox. In the form of the calling sub, prepare a cboSelection with values (1,2,3,4) initialized by form_initialize event. In the same form, use a cmd to pass value selected in cbo to aDVD (object of DVD class) and then show message.

ADV_GIS11 Create methods Simply create a procedure or function within Class code window Public Sub Welcome() MsgBox "Welcomes to the slide show!" End Sub Public Sub SpecialWelcome(strName As String) MsgBox strName & ", welcome to the slide show!" End Sub Call methods from frmMain>cmdClick() Dim CallClass As Class1 Set CallClass = New Class1 CallClass.Welcome CallClass.SpecialWelcome “Peter”

ADV_GIS12 clsMyFirstClass –Create a class in your project 'General Declaration section Private mvarTitle As String 'Write property Public Property Let Title(NewTitle As String) mvarTitle = NewTitle End Property 'Read property Public Property Get Title() As String Title = mvarTitle End Property ‘Method Public Sub Welcome(strMsg As String) MsgBox strMsg End Sub

ADV_GIS13 Instance of Object (Form with cmdCall control) Private Sub cmdCall_Click() Dim myObject As Object Set myObject = New objFirst Dim mTitle As String Dim nTitle As String mTitle = InputBox("Type in title here") 'Set myObject's title as mTitle myObject.Title = mTitle 'Get title from myObject nTitle = myObject.Title 'Show title of myObject using MsgBox MsgBox "The title of object is " & nTitle myObject.Welcome "Hello World, Hello World" End Sub

ADV_GIS14 Interface - part of Component Object Model(COM) A logical group of methods and properties for a class. It may be based on the level of generality or on some other similarity of use or purpose. For example, Human and Dog (by convention, interface names start with the letter “I,” shown w/ lollipops) Dog WagTail Bark Catch Frisbee Name Eat Breathe Handshake Smile Name Eat Breathe Human IGreeting IAnimal IBehavior Both Human and Dog class have IAnimal interface. The IBehavior in Dog and IGreeting in Human are unique to themselves. You want to set a Human or Dog’s name, you need to go through the IAnimal interface

ADV_GIS15 Procedure for accessing methods/properties of components To access the methods/properties of components  1) Declare an object as the interface (Dim pHuman As IGreeting)  2) point the object variable to a new instance of the component (Set pHuman = New Human)  3) Access the methods/properties (pHuman.HandShake, pHuman.Smile)  4) you can only access those properties/methods supported by the declared interface. If you want to access other methods/properties, you need to use the QueryInterface process.

ADV_GIS16 QueryInterface Allows an object variable of one interface to access properties/methods of other interfaces of the same component. Dim pHuman As IGreeting Set pHuman = New Human pHuman.HandShake pHuman.Smile ‘Using QueryInterface to access properties and methods of the IAnimal interface Dim pAnimal As IAnimal Set pAnimal = pHuman pAnimal.Eat pAnimal.Breathe Handshake Smile Name Eat Breathe Human IGreeting IAnimal point the variable to the object variable of other interface or do the error-checking first If TypeOf pHuman Is IAnimal Then

ADV_GIS17 QueryInterface – examples from book and arcobjectonline.esri.com, (g:/classes/4850/w_arcObjectStartSlides.pdf)

ADV_GIS18

ADV_GIS19

ADV_GIS20

ADV_GIS21

ADV_GIS22 ‘Create a dog and Set Color Dim pPet as IPet Set pPet = New pDog pPet.Color = “Golden” pPet.Name = “Rover” Switching Interfaces from one to another One dog only……………..

ADV_GIS23

ADV_GIS24 Interfaceless Class and Interfaced Class Dim e As Elephant Set e = New Elephant E.Name = “Big Ears” 1)Choose appropriate Interface to work with, such as Name property in IMap interface of Map. 2) Declare the variable as IMap instead of Map class, but still set to New Map. Dim pMap as IMap Set pMap = New Map pMap.Name = “My Map” ‘Accessing Extent property, then a new Interface will be used. Dim pActiveView As IActiveView Set pActiveView = New Map pActiveView.Extent = someNewExent To view diagram - Open it from C:\Program Files\ArcGIS\De veloperKit\Diagr ams

ADV_GIS25 Using IApplication and IDocument ArcMap starts, two objects are in use – Application and MxDocument. The name of Application object variable is “Application” and the name of the MxDocument object variable is “ThisDocument” (all begin with p). Caption:String Name: String PrintPreview Application IApplication Two-sided barbell: get and set values Left-sided barbell: get value only Arrow: method

ADV_GIS26 Another Example of QI Dim pPoint As IPoint Set pPoint = New Point pPoint.X = 100 ‘You may use pPoint.PutCoords 100,100 pPoint.Y = 100 Dim pTopoOptr As ITopologicalOperator Set pTopoOptr = pPoint Dim pBufferGeo As IPolygon Set pBufferGeo = pTopoOptr.Buffer(20)