Return to IFS 110 class Notes Menu!

Project 2
Working with Intrinsic Controls and ActiveX Controls

Intrinsic Controls

ActiveX Controls

ActiveX Controls

Building a Project
3 Step Process

  1.  Create the Interface
  2.  Set Properties
  3.  Write Code

Form Size and Position

Labels and AutoSize Property

Labels and Backstyle Property

Copying Controls

List Box Control

Combo Box Control

Shape Control

Check Box Control

Frame Control

Used as a container for other controls
Differences from Shape Control
  1. Only rectangular shape
  2. frame can have caption
  3. Only one option button can be selected at a time when inside a frame (mutually exclusive)

Option Button Control

Option Buttons continued

TextBox Controls

Common Dialog Control

Common Dialog Control

Color Dialog Box
Actions User’s Perspective

  1. Color was selected in the dialog box
  2. the OK button was chosen
  3. a control’s color then changed to the selected color
Note: movie theater attendant will not be able to change the Movie Box Office application’s color. Programmer can use the Color dialog box to show different color possibilities to ANC management
(double-click on form to activate - no directions given to user for this)

Aligning Controls

Setting Properties
Naming Controls

Note: As controls are added to form Visual Basic assigns a name to control (Default Command1)

Note: Easier to read and edit code if controls have names that represent purpose of control within application. (Better cmdOK)

Visual Basic Controls Prefixes (Table 2-2 VB 2.27)

Control

CheckBox
ComboBox
CommandButton
Data
DirList Box
DriveListBox
FileListBox
Form
Frame
Grid
HS scrollBar
Image

Prefix

chk
cbo
cmd
dat
dir
drv
fil
frm
fra
grd
hsb
img

Control

Label
Line
ListBox
Menu
OLE
OptionButton
PictureBox
Shape
TextBox
Timer
VScrollBar

Prefix

lbl
lin
lst
mnu
ole
opt
pic
shp
txt
tmr
vsb

 

 

Adding Items to Drop-Down List
(2 Ways)

  1. Design-Time - add items to ComboBox or ListBox control by adding items to the control’s List property
  2. Run-Time - use AddItem method using code
example: (put in Form_Load procedure)

Setting Label Properties

Visible Property

Default Property
Command Buttons

Writing Code

  • Assignment statements
  • Controlname.property = value

    Example:

    cmdEnter.Default = True

    To Save the Form (Steps)

    1. Click the Save Project button Save Project Icon from Toolbar on Standard toolbar
    2. Type Name of Form in File Name box in the Save File As dialog box
    3. Click Floppy drive A in the Save in list box
    4. Click the button in the Save File As dialog box
    5. Type Name of Project in File Name box in the Save Project As dialog box
    6. Click the button in the Save Project As dialog box

    Movie Box Office Application

    General Declarations Subroutine

    Rules Variable Names

    Variables Continued

    Example:

    rate = 3.5 or name = "John"

    Code that Creates Variables

    EXAMPLE TYPE

    numeric data

    string data

    another variable

    expression

    STATEMENT

    price = 1.35

    movie = "ET"

    cost = price

    net = grosspay - taxes

    Implicit and Explicit Variables

    Dim variablename As datatype

    Variables Continued

    Lose their value between calls unless they are declared static

    Declaration Statement

    Dim variablename As datatype

    Example:

    Dim num As Integer

    Note: Case and color automatically changed

    Note: VB inspects code for common errors when ENTER key pressed at end of line.

    Editor Options

    Creating Procedures
    Several Controls (Steps)

    1. Select control to assign code from Object list box
    2. Select desired event from Procedures list box
    3. Enter code statements

    Order Of Precedence

    TABLE 2-7 VB 2.45

    ^ Exponents

    * Multiplication

    / Division returning floating-point result

    \ Division returning integer result

    MOD Divide two numbers returning remainder

    + Addition

    - Subtraction, negative value of expression

    (parenthesis used to change order of operations)

     

    If... Then...Else Statement
    Single - line

    General format:

    If condition Then true-task Else false-task

    Condition - is made up of two expressions and a relational operator.

    Example: If chkMatinee.Value = 1 Then price = 3.5 Else price = 5

     

    RELATIONAL OPERATORS
     (Table 2-8 VB 2.46)

    Comparison Operator

    =
    <
    >
    <=
    >=
    <>

    Meaning

    is equal to
    is less than
    is greater than
    is less than or equal to
    is greater than or equal to
    is not equal to

    Format$ function

    Format$ (expression, predefined format name)

    Example:

    Format$ (grosspay, "currency")

    Note: function must be called in an expression can not be used by itself

    Control.property = Function (argument list)

    Format$ function

    lblAmtdue.Caption = Format$ (num * price, "currency")

    Note: $ character appended to Format tells VB to change numeric result of expression to a string before it is assigned to caption of label

    Option1_Click Subroutine
    (3 options)

    1. Num variable assigned to number of tickets
    2. Determine ticket price
          Value property of check box is 1 if checked 0 if not
    3. Calculate amount due (num*price)
          display it as dollars and cents in Amount Due box

    Coding Option1_click

    Sub Option1_Click ( )

    ‘calculate and display amount due

    num = 1

    If chkMatinee.Value = 1 Then price = 3.5 Else price = 5

    lblAmtdue.Caption = Format$(num * price, "currency")

    End Sub

    cmdEnter_Click Subroutine

    String Data Functions

    name$ = title$ & " " & firstname$ & " " & lastname$

    Constants

    Combo List Box Principles

    Code cmdEnter_Click

    Sub cmdEnter_Click ( )

    ‘Update transaction list and clear settings

    txtRecord.Text = num & " " & cboShow.Text & vbNewLine & txtRecord.Text

    cboShow.Listindex = -1 ‘list box empties selects blank list item

    chkMatinee.Value = 0 ‘uncheck matinee box

    Option5.Value = True ‘select invisible button

    lblAmtdue.Caption = "" ‘clear caption

    End Sub

    CommonDialog Control Code

    Project 2
    Working with Controls
    END

    Program Creating Drop-Down Application Requirements

    Return to IFS 110 class Notes Menu!