Return to IFS 110 class Notes Menu!

 

Project 5
Drag-and Drop Events and More Complex Code Structures


Traffic Sign Tutorial

Options Menu (3 commands)

  1. Clear - returns all signs to their original locations
  2. Show - places the signs in their correct containers
  3. Quiz - presents a series of three questions about the shapes of the signs

Creating the Interface

Uses of Controls

Dragging and Dropping Code

Dragging and Dropping Code

Dragging and Dropping Terms

Dragging and Dropping Code

Note: Much of the apparent movement is the result of changing the values of the Picture and Visible properties.

DragMode Property

Setting Properties (steps)

Setting Properties
imgSign Array Controls

DragIcon Property

Note: When dragging initiated during run-time, only an outline of control is moved across the desktop.

Sign Icons

Writing Code

Example: Source.Visible = False (invisible for any control being dragged over)

DragOver Subroutine

Note: changing the source control's Visible property to False does not affect the source control's DragIcon property (drag icon is still visible)

DragDrop Subroutine

Sub ctrlName_DragDrop (Source As Control, X As Single, Y As Single)

DragDrop Subroutine

Example: can use the DragDrop event to move the source control to a new location or change the Visible property of the source control

Traffic Sign Code Activities

General_Declarations Sub

Declaring Variables

Type-Declaration Characters

Example: 
$ sign used for strings, % sign used for integers 
Dim num%

Three-letter Prefixes Variables

Visual Basic Data Types
(see Table 5-4 VB 5.28)

Byte - 1 byte positive integer from 0 - 255
Boolean
- 2 bytes two possible values, True or False
Integer - 2 bytes whole numbers 32,767
%
Long - 4 bytes whole numbers 2 billion
&
Currency - 8 bytes dollars and cents
@
Single - 4 bytes numbers with decimals
!
Double - 8 bytes large decimal values
#
Date
- 8 bytes store dates and times as real number
String - 1 byte/chr up to 65,500 bytes
$
Object
- 4 bytes represents any Object reference (address)
Variant
- As needed numeric value up to the range of Double
User-defined
- any data type defined using the Type statement

frmTraffic_Load Sub

imgSign(0).DragIcon = imgSign(0).Picture

Form_DragOver Sub

Other DragDrop Subroutines

imgContainer_DragDrop Sub

imgContainer_DragDrop Sub

Procedures Advantages

  1. No duplication of effort
  2. Reduces the length of a program
        saves memory space
        reduces complexity
  3. Code can be shared with other projects
        saves time when coding new projects

Calling Clear Procedure

mnuClear_Click (calls subroutine)

mnuClear_Click Subroutine

Returning Signs involves 2 Actions
  1. Clearing pictures from container images
         (setting Picture property to Picture property of imgBlank control)
  2. Setting Visible property of imgSign controls array to True
        (each sign appears to return to its original location)
Note: Subroutine also resets the value of NumCorrect% to 0

mnuShow_Click Subroutine

mnuQuiz_Click Subroutine

INPUTBOX FUNCTION

Select Case (extension of If)
see Table 5-6 VB 5.39

Select Case textexpression

Case expression1
        statementblock-1

Case expression2
        statementblock-2

Case Else
       
statementblock-n

End Select

Select Case Example

Select Case MaritalStatus

Case Is = 1
    Debug.Print "Marital Status is Single"

Case Is = 2
    Debug. Print "Marital Status is Married"

Case Else
   
Debug. Print "Marital Status is Invalid"

End Select

Do Until loop Syntax

Do Until condition (header statement)

statementblock

Loop (terminator statement)

Do - 1st statement in control structure

statementblock - statements repeated

Until - indicates loop executed until condition is True

condition - numeric or string that evaluates to True

Do Until loop Example

Sub Form_Load ( )

'Prints values 0 to 9 to the Immediate Window

Dim Count As Integer

Count = 0

Do Until Count = 10
    Debug.Print Count
    Count = Count + 1
Loop

End Sub

UCase$ function

Syntax:

UCase$ (stringexpr)

Example:

teststring = "pete rose"

Name$ = UCase$ (teststring)

returns a value of "PETE ROSE" in Name$

Project 5
Drag-and Drop Events and More Complex Code Structures

END

Creating and Using a DragDrop Event Procedure Requirements

Return to IFS 110 class Notes Menu!

Click for Printer Version