Chapter 3: Creating ActiveX Controls By Noppadon Kamolvilassatian Dept. of Computer Engineering, Prince of Songkla University Source: Mastering Visual.

Slides:



Advertisements
Similar presentations
Sep-05 Slide:1 VBA in Excel Walter Milner. Sep-05 Slide:2 VBA in Excel Introduction VBA = Visual Basic for Applications Enables end-user programming In.
Advertisements

What Was I Thinking??. Key Terms 1. Control 1. Control 2. Design Mode 2. Design Mode 3. Event 3. Event 4. Form 4. Form 5. Interface 5. Interface 6. Properties.
Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
Java Programming, 3e Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
Visual Basic: An Object Oriented Approach 10 - Polymorphism.
Exploring Office Grauer and Barber 1 Creating More Powerful Applications: Introduction to VBA(Wk9)
VB Code Statements 3 types of VB statement The Remark statement, known as comments, are used for project documentation only Begin with an apostrophe Not.
To type the VB code behind the command button (named cmdPush), Double-Click on the Push Me (caption) command button As a result the Visual Basic Code Window.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
1/26/2004 PPCC - Introduction to VB6 Copyright ©2004, Tore Bostrup 1 Introduction to VB6 Materials & Prerequisites Course Outline Background Information.
VB DATATYPES, VARIABLES, CONSTANTS & CALCULATIONS.
Introduction to Class Modules Please use speaker notes for additional information!
Sep-05 Slide:1 ActiveX Controls in VB ActiveX Controls in VB6.
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
1 Integrated Development Environment Building Your First Project (A Step-By-Step Approach)
McGraw-Hill© 2007 The McGraw-Hill Companies, Inc. All rights reserved. 1-1.
Visual Basic: An Object Oriented Approach 12 – Creating and using ActiveX objects.
Microsoft Visual Basic 2005: Reloaded Second Edition
CIS 338: Creating ActiveX Controls Dr. Ralph D. Westfall March, 2003.
Module 7: Object-Oriented Programming in Visual Basic .NET
Obsydian OLE Automation Ranjit Sahota Chief Architect Obsydian Development Ranjit Sahota Chief Architect Obsydian Development.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Using Visual Basic 6.0 to Create Web-Based Database Applications
Chapter 2: Creating ActiveX Code Components By นภดล กมลวิลาศเสถียร Dept. of Computer Engineering, Prince of Songkla University Source: Mastering Visual.
Why to Create a Procedure
® Microsoft Access 2010 Tutorial 11 Using and Writing Visual Basic for Applications Code.
Multiple Forms, Container Controls, AddHandler This presentation is based on the Forms and ContainerControls VB Projects 1.
Chapter 1: Creating ActiveX Clients By Noppadon Kamolvilassatian Dept. of Computer Engineering, Prince of Songkla University Source: Mastering Visual Basic.
Introduction to Visual Basic.NET Chapter 2 Introduction to Controls, Events.
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.
Outline Software and Programming Program Structure Tools for Designing Software Programming Languages Introduction to Visual Basic (VBA)
SYSTEMSDESIGNANALYSIS 1 OO: Chapter 9 Visual Basic: Building Components Jerry Post Copyright © 1999.
MS Visual Basic Applications Walter Milner. Event-driven programming Standard approach for GUIs Contrast with old character interfaces – program determines.
University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Programming in Microsoft Access using VBA Using VBA to add functionality.
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
Chapter Two Creating a First Project in Visual Basic.
Programming with Visual C++: Concepts and Projects Chapter 2B: Reading, Processing and Displaying Data (Tutorial)
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
MS Visual Basic 6 Walter Milner. VB 6 0 Introduction –background to VB, A hello World program 1 Core language 1 –Projects, data types, variables, forms,
Visual Basic Programming Introduction VB is one of the High level language VB has evolved from the BASIC language. BASIC stands for Beginners All-purpose.
CS 101 Test 2 Study Guide Acronyms RAD - Rapid Application Development IDE - Integrated Development Environment GUI - Graphical User Interface VB - Visual.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
Chapter 11: Introduction to VBA Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
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.
1 Writing Software Kashef Mughal. 2 Algorithms  The term algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving a problem.  An Algorithm.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al-ajmi Chapter 2 Introduction to Visual Basic Programming Visual Basic.NET.
Controlling Program Flow with Decision Structures.
COMPREHENSIVE Access Tutorial 11 Using and Writing Visual Basic for Applications Code.
Visual C++ Programming: Concepts and Projects Chapter 10B: Recursion (Tutorial)
‘Tirgul’ # 5 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #5.
Course ILT Using complex selection structures Unit objectives Include radio buttons and check boxes in an interface, create and call a user- defined Sub.
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
Sub Procedures and Functions Visual Basic. Sub Procedures Slide 2 of 26 Topic & Structure of the lesson Introduction to Modular Design Concepts Write.
Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #5
VBA - Excel VBA is Visual Basic for Applications
1. Introduction to Visual Basic
Introduction to VB6 Week 1 3/2/2004 PPCC - Introduction to VB6
Module 0: Introduction Chapter 2: Getting Started
Module 1: Getting Started
Objectives Learn about Function procedures (functions), Sub procedures (subroutines), and modules Review and modify an existing subroutine in an event.
Variables and Arithmetic Operations
VISUAL BASIC.
Microsoft Visual Basic 2005 BASICS
CIS16 Application Development Programming with Visual Basic
Chapter 8 - Functions and Functionality
Visual Basic CSC
CHAPTER FOUR VARIABLES AND CONSTANTS
Presentation transcript:

Chapter 3: Creating ActiveX Controls By Noppadon Kamolvilassatian Dept. of Computer Engineering, Prince of Songkla University Source: Mastering Visual Basic 5, Microsoft Corporation

Objectives Describe the benefits of using ActiveX controls. Describe the benefits of using ActiveX controls. Describe how an ActiveX control differs from an ActiveX Automation Server. Describe how an ActiveX control differs from an ActiveX Automation Server. Create an ActiveX control. Create an ActiveX control. Test and debug an ActiveX control. Test and debug an ActiveX control. Expose properties, methods, and events of an ActiveX control. Expose properties, methods, and events of an ActiveX control.

Overview: Introduction to Controls Controls are reusable objects that include visual elements and code. Controls are reusable objects that include visual elements and code. Controls must be placed in some type of container, such as a form or an application. Controls must be placed in some type of container, such as a form or an application.

Control Classes Control Class (.ctl) acts as a template for that control. When you place a control on a form, you create an instance of that control. Control Class (.ctl) acts as a template for that control. When you place a control on a form, you create an instance of that control.

Control Components A control component (.ocx) can provide more than one kind of control. A control component (.ocx) can provide more than one kind of control.

Controls vs. Code Components A code component exposes functionality and can be used by other applications through Automation. A code component exposes functionality and can be used by other applications through Automation. Control components contain visual elements that can generate events based on user actions. Control components contain visual elements that can generate events based on user actions.

Controls vs. Code Components

The UserControl Object A foundation for building controls. A foundation for building controls. Source code and property values of a UserControl object -->.ctl (compare.frm) Source code and property values of a UserControl object -->.ctl (compare.frm) Graphics -->.ctx (compare.frx) Graphics -->.ctx (compare.frx)

Options for Distributing Controls as compiled components as compiled components as source code as source code

Steps for Creating an ActiveX Controls: Demonstration 1.Create the user interface for the control. 2.Provide the properties and methods of the control. 3.Define how the control will react to events. 4.Add property pages for the control. 5.Debug and test the control.

Creating a Control’s User Interface Adding Constituent Controls: in the same way as adding controls to a standard VB form. Adding Constituent Controls: in the same way as adding controls to a standard VB form.

Testing a Control You must test the control’s design-time functionality. You have to create another project that you use to test it. You must test the control’s design-time functionality. You have to create another project that you use to test it. Creating a test project. Debug the control in the same way as debugging an in-process component. Creating a test project. Debug the control in the same way as debugging an in-process component.

Exposing Properties, Methods, and Events Adding Properties Adding Properties Adding Methods Adding Methods Exposing Named Constants Exposing Named Constants Raising Control Events Raising Control Events Using the ActiveX Control Interface Wizard Using the ActiveX Control Interface Wizard

Adding Properties: Creating a Property To indicate that a property value has changed, use the PropertyChanged method. To indicate that a property value has changed, use the PropertyChanged method. Public Property Get Name()As String Name = txtName.Text End Property Public Property Let Name(ByVal NewName As String) txtName.Text = NewName PropertyChanged "Name" End Property

Exposing Properties of Constituent Controls Public Property Get Caption()As String Caption = lblName.Caption End Property Public Property Let Caption(ByVal NewCaption As String) lblName.Caption = NewCaption PropertyChanged "Caption" End Property

Mapping a Property to Multiple Controls Public Property Get ForeColor() As OLE_COLOR ForeColor = MyControl.ForeColor End Property Public Property Let ForeColor(ByVal NewfColor As OLE_COLOR) Dim ctlElement As Object MyControl.ForeColor = NewfColor For Each ctlElement In Controls If(TypeOf ctlElement Is Label) _ Or (TypeOf ctlElement Is CheckBox) _ Then ctlElement.ForeColor = NewfColor Next PropertyChanged "ForeColor" End Property

Adding Methods: Creating a Method Public Sub ShowDate() MsgBox "Date is: " & Now() End Sub

Exposing Methods of Constituent Controls Public Sub IDFocus() txtEmpID.SetFocus End Sub Private Sub cmdSetIdFocus_Click() MyControl.IDFocus End Sub

Exposing Named Constants (Enumerations) A convenient way to group a set of related named constants and associate them with constant values. A convenient way to group a set of related named constants and associate them with constant values. Public Enum TempBoilCelsius msubWater = 100 msubIron = 2750 msubNitrogen = msubGold = 2807 End Enum

Raising Control Events Received Events vs. Raised Events Received Events vs. Raised Events – –You use the events your control receives to add functionality to your control. – –A developer that uses your control can use events the control raises to add functionality to the control.

Raising Control Events Raising a Control Event Raising a Control Event –First declare the event, then use the RaiseEvent statement to call the event. 'Declare a public Click 'event with no arguments. Public Event Click() The following line of code raises the Click event: RaiseEvent Click

Exposing Constituent Control Events n Declare a new event in the UserControl object n In the constituent control’s event, raise your own event. Public Event MyKeyPress(KeyAscii As Integer) Private Sub Text1_KeyPress(KeyAscii As Integer) RaiseEvent MyKeyPress (KeyAscii) End Sub

Using ActiveX Control Interface Wizard Demonstration Demonstration

Distributing a Control: Licensing Controls Purpose: prevents other developers from using your control to create their own control. Purpose: prevents other developers from using your control to create their own control. To use lincensed constituent control as a part of a control: To use lincensed constituent control as a part of a control: –Users of your control must have the controls installed or –the control vendor includes the lincensing key with the control’s setup program.

Distributing a Control: Creating a Control Setup Program Use the Application Setup Wizard Use the Application Setup Wizard (optional) Demonstration (optional) Demonstration

Lab: Creating ActiveX Control Demonstration Demonstration

Assessment 4. What is the major benefit of using named constants (enumerations)? 5. Consider the following code: Public Property Get Caption()As String Caption = lblName.Caption End Property What is the difference between the variable ‘Caption’ and ‘lblName.Caption’? 6.There is an important distinction between the events received by your UserControl object (or by its constituent controls) and the events your control raises. What is the difference between the uses of these two types of events?

Lab Report (Handed in by...) Your lab report should contain the following things: 1. Answers to the assessment questions. For the first three questions, give the correct answers with explanations. 2. Complete code of exercise 1, 2,and 3 with explanations of the statements in the code.