Return to IFS 110 class Notes Menu!

Project 7
Creating ActiveX Controls and
Distributing Applications

Introduction

Introduction

Introduction

Multiplication Quiz

Creating ActiveX Controls

3 Ways to Create Controls

  1. Create control from scratch
  2. Modify a single existing control
  3. Assemble a new control from several existing controls
In this project, assemble a StopWatch control from existing Label, CommandButtons, and Timer controls

Creating a User Control Interface

StopWatch Control

  • see (Figure 7- 13 VB 7.11)
  • Timer Control

    Timer Control

    Timer Control

    Writing UserControl Event Procedures

    Resize Event

    Timer Operations

    Writing UserControl Property Procedures

    Writing UserControl Property Procedures

    Property Procedures

    StWatch Control
    (2 additional properties)

    1. Buttons property - gives the user a choice of whether or not the 3 command buttons in StWatch are visible
    StWatch1.Buttons = False (will change Visible property of 3 constituent CommandButtons to False)

    StWatch Control
    (2 additional properties continued)

    2. Action property - values of 1(Start), 2(Stop), or 3(Reset) will change the Value property of the corresponding CommandButton control to True using code

    Properties or Methods ?

    CommonDialog1.ShowColor
    CommonDialog1.Action = 3

    WriteProperties Event

    example - Borderstyle property of label set to 1-Fixed Single, when application closed and reopened property maintained

    WriteProperties Method
    ( 3 arguments)

    1. String expression - represents data value to be placed in property bag
    2. Data value to save in property bag
    3. Default value for data

    Call PropBag.WriteProperty ("Caption",Label1.Caption,"Label 1")

    WriteProperty method of PropertyBag object used to write a value of property

    ReadProperties Event

    ReadProperties Method
    (2 arguments)

    1. String expression representing a data value in the property bag
    2. Value to be returned if no value is present in the property bag

    Label1.Caption = PropBag.ReadProperty ("Caption", "Label 1")

    PropertyChanged Method

    Saving ActiveX Project

    Adding Multiple Projects

    Compiling ActiveX Control

    2 Disadvantages to Above Method:
    1. Newer version of control forces the project to be rebuilt
    2. Every project using control would need the .ctl file in its .exe file
    Solution - .ocx control available to all applications easy to replace with updated version

    Multiplication Quiz Application
    (Setting Properties CommandButton)

    Writing Code

    3 event procedures see (Table 7-8 VB 7.37)
    1. Form_Resize - used to keep controls centered within application’s window when user resizes it
    2. cmdStart_Click - resets answer text boxes BackColor property; generates 5 problems; reset StWatch control
    3. cmdStop_Click - must stop StWatch control and grade the answers

    Form_Resize Event
    (Respond to 3 different states)

    1. User minimizes form - do nothing
    2. Not minimized and user drags width less than original - return to original width
    3. User makes width greater than original (drags or maximizes) - reposition controls

    Form_Resize Code

    If frmMultQuiz.WindowState = 1 Then

    ‘do nothing

    ElseIf frmMultQuiz.Width < 6780 Then

    frmMultQuiz.Width = 6780 ‘user made form too small

    Else ‘user made form bigger than original

    Frame1.Left = (frmMultQuiz.ScaleWidth - _ Frame1.Width - 345 - 975) / 2

    cmdStart.Left = Frame1.Left + Frame1.Width + 345

    cmdStop.Left = Frame1.Left + Frame1.Width + 345

    StWatch1.Left = Frame1.Left + Frame1.Width + 345

    End If

    Random Number Functions

    Random Numbers Terms

    Int ((upperbound - lowerbound + 1) * Rnd + lowerbound)

    cmdStop_Click Event

    Distributing Applications

    Distributing Applications

    1. Requires more than one floppy - files must be transferred to hard drive
    2. Need some way to tell user what folders to copy files to
    3. If user copies .dll or .ocx file over a newer version used by another application, VB program will work but other application won’t
    4. User will have to add program group and include it on the Start menu

    Distributing Applications Solution

    Packaging a Setup Program

    Installing, Running, Applications