Mouse Events. Mouse Driven Events Unlike control_click() which is passed no arguments (unless it's an index for an array), MouseDown, MouseUp and MouseMove.

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.
1.
Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
Microsoft Visual Basic 2010: Reloaded Fourth Edition
1 Visual Basic Programming II Lecture 3 MIS233 Instructor – Larry Langellier.
Programming with Microsoft Visual Basic 2005, Third Edition
VB Default Controls List Box, Combo Box
Arrays-Part 1. Objectives Declare and initialize a one-dimensional array Store data in a one-dimensional array Display the contents of a one-dimensional.
Arrays.
CVEV 118/698 Visual Basic Lecture 3 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar.
1 Chapter 7 Arrays. 2 Outline and Objective In this chapter we will Learn about arrays One-dimensional arrays Two-dimensional arrays Learn about searching.
Chapter 7: Sub and Function Procedures
Chapter 7 - Visual Basic Schneider
Lec4 P 1 CP2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton CP2030 VBFC Lecture 4 Back To Index v Iteration - Looping v Arrays.
VB .NET Programming Fundamentals
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Tutorial 7: Sub and Function Procedures1 Tutorial 7 Sub and Function Procedures.
Programming with Microsoft Visual Basic 2012 Chapter 7: Sub and Function Procedures.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
1 Microsoft Visual Basic 2010 Arrays. 2 Using a One-Dimensional Array Lesson A Objectives After completing this lesson, you will be able to:  Declare.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
Microsoft Visual Basic 2005 CHAPTER 9 Using Arrays and File Handling.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
Using Arrays and File Handling
Array Processing Simple Program Design Third Edition A Step-by-Step Approach 7.
Tutorial 61 List Box Control Can be used to display a set of choices from which the user can select only one You also can create multi-selection list boxes.
Chapter 8 Arrays Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Programming with Microsoft Visual Basic 2008 Fourth Edition
Copyright © 2001 by Wiley. All rights reserved. Chapter 5: The Repetition Process in Visual Basic Event Driven Loops Determinate Loops Indeterminate Loops.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Chapter 9 - VB.Net by Schneider1 Chapter 9 – Additional Controls and Objects 9.1 List Boxes, Combo Boxes, and the File-Opening Control The List Box Control.
ListBox, ComboBox, Menu Chapter 5.4, ComboBox Control: Properties & Methods u Combines TextBox features with a short drop- down list  cboOne.AddItem(string)
Using Client-Side Scripts to Enhance Web Applications 1.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Working with option button, check box, and list box controls Visual Basic for Applications 13.
Chapter Six: Working With Arrays in Visual Basic.
© 1999, by Que Education and Training, Appendix A, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
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
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
An Introduction to Programming with C++ Fifth Edition Chapter 11 Arrays.
Computer Programming TCP1224 Chapter 11 Arrays. Objectives Using Arrays Declare and initialize a one-dimensional array Manipulate a one-dimensional array.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
1 Working with Data Structures Kashef Mughal. 2 Chapter 5  Please review on your own  A few terms .NET Framework - programming model  CLR (Common.
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.
Lab 6 (2) Arrays ► Lab 5 (1) Exercise Review ► Array Concept ► Why Arrays? ► Array Declaration ► An Example of Array ► Exercise.
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 4 Working with Variables, Constants, Data Types, and Expressions.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley More About Array Processing 8.2 There Are Many Uses of Arrays and Many Programming.
Tutorial 101 Variable Arrays A group of variables that have the same name and data type and are related in some way Can have as many as 60 dimensions.
Chapter 9 Processing Lists with Arrays. Class 9: Arrays Understand the concept of random numbers and how to generate random numbers Describe the similarities.
Programming with Microsoft Visual Basic th Edition
Tutorial 3: Using Variables and Constants1 Tutorial 3 Using Variables and Constants.
Programming with Microsoft Visual Basic 2012 Chapter 9: Arrays.
1 Chapter 7 Arrays. 2 Outline and Objective In this chapter we will Learn about arrays One-dimensional arrays Two-dimensional arrays Learn about searching.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Controlling Program Flow with Decision Structures.
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.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Lab 5 Arrays ► Lab 4 Exercise Review ► Array Concept ► Why Arrays? ► Array Declaration ► An Example of Array ► Exercise.
IS 350 Arrays.
Variables and Arithmetic Operations
Microsoft Visual Basic 2005: Reloaded Second Edition
CIS 16 Application Development Programming with Visual Basic
Tutorial 11 Arrays Tutorial 11: Arrays.
CIS16 Application Development and Programming using Visual Basic.net
Introduction to Computer Programming IT-104
Presentation transcript:

Mouse Events

Mouse Driven Events Unlike control_click() which is passed no arguments (unless it's an index for an array), MouseDown, MouseUp and MouseMove events have much more information available –Button as integer - which mouse button(s) were pressed –Shift as integer - which modifier keys were pressed –X and Y as single - the location of the mouse pointer in the coordinate system of the object receiving the mouse event

Mouse Driven Events (2) Button –Status of the mouse buttons 1 - Left Button 2 - Right Button 4 - Middle Button –Multiple buttons are treated as multiple events for MouseUp and MouseDown

Mouse Driven Events (3) Shift –Keys (Shift, Control and Alt) 1 - Shift Key 2 - CTRL Key 4 - ALT Key –Any or all of the modifier keys can be set

Mouse Driven Events (4) For the Button or Shift arguments, bitwise logical testing must be performed to determine state. Examples –(shift AND 3) = 3 tests for Shift and CTRL keys pressed –(Button AND 2) = 2 tests Right button only –(Button AND 3) = 2 tests for Right button only

Mouse Positioning Example #1 Create a form with a textbox and code: Private Sub Form_MouseUp(...) moveit = False end sub Private Sub Form_MouseDown(...) moveit = True Call Form_Mousemove(Button, Shift, X, Y) End Sub Private Sub Form_MouseMove(…) If moveit Then Text1.Move X, Y End Sub

Mouse Positioning Example #2 Etch-a-sketch Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Line -(X, Y) End Sub

Mouse Positioning Example #3 Improved Etch-a-sketch dim moveit Private Sub Form_Mousemove(…, X, Y) If moveit Then Line -(X, Y) : rem circle (x,y), 50 End Sub Private Sub Form_MouseUp(…, X, Y) Form1.CurrentX = X Form1.CurrentY = Y Call Form_Mousemove(Button, Shift, X, Y) moveit = Not (moveit) End Sub

Mouse Click, Up, Down What occurs in what sequence? –Mouse Down is first –Mouse up is second –mouse click is third –mouse up always follows a double click –mouse move always follows a mouse click

List / Combo Boxes

Three types of list controls List controls –Drop-down list –Combo-Box The last set is “initialized” with the contents of the appropriate drive directory These two must be initialized via code

List Box Control Allows the user to select from a specified set of options (but he cannot enter an unlisted value) Presented as a single window with the items listed sequentially Selections must be initialized via code (often as part of form_load) The columns property permits display of multiple columns of data in a snaking fashion (horizontal scroll as well as vertical scroll) The multiSelect property allows selecting multiple items which are placed in the list property (an array ) and identified by the selected property (an array) –selected(i) = true indicates that the related element of list(i) has been selected

AddItem Method Used to add items to a list box Syntax –control.AddItem item –item is the expression you want displayed, and it can be either numeric or string –if item is a literal string constant, then it must be enclosed in quotation marks

Arrangement of List Box Items By use, with the most used entries appearing first in the list Sorted in ascending order either alphabetically, numerically, or chronologically

Sorted Property Can be set to either the Boolean value True or the Boolean value False If set the True, the list box items will be sorted in ascending order If set to False, the list box items will appear in the order in which they were entered

ListIndex Property You can use the ListIndex property to refer to an item in the list box The first item in a list box has a ListIndex value of 0 If no items are selected in the list box, the ListIndex property has a value of -1

Default Item It is customary to select a default item in a single-selection list box when the interface first appears –the default item should be either the most used selection or the first selection in the list –lstName.ListIndex = 0 will select the first item in the lstName list box A default selection typically is not made in a multi-selection list box

List Box Initialization Example Dim I, start_pos, stop_pos, months, thismonth thismonth = month(Now) ' note: month returns 1-12 months = "January February March April May June " months = months & "July August September October November December " start_pos = 1 For item_number = 0 To 11 ' item numbers are zero-based stop_pos = InStr(start_pos, months, " ") List1.AddItem Trim(Mid(months, start_pos, stop_pos - start_pos)), item_number start_pos = stop_pos + 1 Next item_number ' note: listindex is 0-based so we have to subtract 1 to get the correct month selected List1.ListIndex = thismonth - 1

Combo Box Control (three styles) Drop Down (Style 0) –Like a one-line text box with a list attached –User can select a value or enter one of his own –Options are not shown unless user displays them Simple Combo Box (Style 1) –Always shows the list of options to the user if you design the box large enough –User can select a value or enter one of his own Drop Down List Box (Style 2) –List is not displayed until user clicks down arrow –User can only select from list of options –Typing in the text box scrolls to best fit option

Lists & Combo Boxes The Integralheight property –if true will force box size to display an integral number of lines and no partial lines –if false will retain box design dimensions, but may display partial lines The listindex property contains the index (0-based) of the selected item (-1 = no item selected) The additem method (not event) is used to add or replace an item The removeitem method is used to remove an item The clear method will remove all items

Lists & Combo Boxes (2) The sorted property sorts the list but can be very slow when adding to large lists The text property contains the last selected item The listcount property contains the number of items, always one more than the maximum listindex The topindex property contains the index value for the top of the displayed portion of the list when there is a vertical scroll bar There are other methods available (Use Object Browser to see them)

List & Combo Box Differences Selected and List properties –only for List Boxes which allow multiple selections Change event –only for combo boxes and only when a new entry is typed in Dropdown event –only for dropdown combo and dropdown list

Variable Arrays

A group of variables that have the same name and data type and are related in some way Can have as many as 60 dimensions in Visual Basic; the most commonly used arrays are one-dimensional and two-dimensional Programmers use arrays to store related data in the internal memory of the computer Data stored inside the computer can be both written and read much faster than data stored in a file on a disk

Variable Arrays A one-dimensional array is simply a row (or column) of variables; a two-dimensional array resembles a table in that it has rows and columns Each element in an array is identified by a subscript You refer to an array element by the array’s name followed by the element’s subscript

Variable Arrays (2) Lower-bound is zero by default unless –option base 1 is declared, in which case it is 1 –it is explicitly declared using the to keyword dim cards(1 to 52) dim line_numbers(100 to 1000) Upper element designated by a long in parentheses after the name - ex. dim cards(51) (an array of 52 items numbered 0-51) Arrays must usually be initialized before use using some kind of looping construct or the array statement dim x(4) x = array(5,7,9,"this",true)

One-dimensional Array NebraskaNew JerseyNew Mexico Tennessee Texas Nebraska New Jersey New Mexico Tennessee Texas

Two-dimensional Array Nebraska New Jersey New Mexico Tennessee Texas Lincoln Trenton Santa Fe Nashville Austin

One-dimensional Array –Dim arrayname(lower subscript To upper subscript) As datatype –Public arrayname(lower subscript To upper subscript) As datatype lower subscript and upper subscript are numbers that define the lowest and the highest subscript in the array –The Dim (and Public) statements create and initialize the array variables in memory

One-dimensional Array –Dim strMonthArray(1 To 6) As String –Dim intSquareArray(1 To 5) As Integer –Dim sngNum(1 To 10) As Single –Dim udtEmp(1 To 20) As EmpStruc –Note: It is not necessary for an array name to contain the word “Array.”

One-dimensional Array strMonthArray(1) = “Jan” strMonthArray(2) = “Feb” strMonthArray(3) = “Mar” strMonthArray(4) = “Apr” strMonthArray(5) = “May” strMonthArray(6) = “June”

One-dimensional Array For intNum = 1 to 5 intSquareArray(intNum) = intNum * intNum Next intNum For intNum = 1 to 10 sngNum(intNum) = Val(InputBox(“Enter number”)) Next intNum

One-dimensional Array Do While Not EOF(1) intNum = intNum + 1 Input #1, udtEmp(intNum).Name, udtEmp(intNum).Salary Loop

Array Initialization Use loops to initialize dim row as integer, col as integer static big_matrix(1 to 5, 1 to 10) as integer for row = 1 to 5 for col = 1 to 10 big_matrix (row,col) = row*10+col next col next row

Calculating the Average Declare variables Repeat for intNum = 1 to 20 by 1 add array score to intTotal variable End repeat for intNum Calculate the average by dividing intTotal by 20 Display the average

Finding the Highest Value Declare variables Assign first array value to intHigh variable Repeat for intNum = 2 to 20 by 1 If current array value > intHigh value then assign current array value to intHigh End If End repeat for intNum Display the highest value(stored in intHigh)

Updating an Array Declare variables Prompt user for the value to add Repeat for intNum = 2 to 20 by 1 add value to current array value End repeat for intNum Display “Updated” message Open a file Repeat for intNum = 1 to 20 by 1 Write array value to file End repeat for intNum Close the file

Two-dimensional Array Dim arrayname(lower subscript To upper subscript, lower subscript To upper subscript) As datatype Public arrayname(lower subscript To upper subscript, lower subscript To upper subscript) As datatype

Two-dimensional Array –Dim strNameArray(1 To 6, 1 To 3) As String –Dim intNum(1 To 5, 1 To 10) As Integer –Dim sngSales(1 To 20, 1 To 2) As Single –Note: It is not necessary for an array name to contain the word “Array.”

Two-dimensional Array Declare variables Open the file Repeat for intRow = 1 to 4 by 1 Repeat for intCol = 1 To 2 by 1 Read name from file and store it in the current array element End repeat for intCol End repeat for intRow Close the file