VB Objects & Events (Exercises) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 3, Friday 1/31/2003)

Slides:



Advertisements
Similar presentations
CE 311 K Introduction to Computer Methods VB Controls and Events Daene C. McKinney.
Advertisements

VISUAL BASIC Visual Basic is derived from the Basic language (Beginner’s All-Purpose Symbolic Instruction Code) Visual Basic uses an event-driven programming.
Chapter 1: An Introduction to Visual Basic 2012
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Excel Project 7 Using Macros and Visual Basic for Applications (VBA) with Excel.
Using Macros and Visual Basic for Applications (VBA) with Excel
List box & Combo box controls School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 14, Monday 4/21/2003)
Chapter 2 –Visual Basic, Controls, and Events
Introduction to Visual Basic Programming. Lecture Outline History What is Visual Basic First Look at the VB 6.0 Environment Some VB Terminology Our first.
Introducing More Controls Text boxCheck box Option button Command button frame image.
The Initial Visual Basic Screen
Flowchart Start Input weight and height
Introduction to Computing Dr. Nadeem A Khan. Lecture 11.
Introduction to computers & Visual Basic School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 3, Monday 1/27/2003)
Introduction to Computing Dr. Nadeem A Khan. Lecture 13.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab2 Managing Controls.
Chapter 31 Visual Basic Controls A Form is a windows-style screen displayed by Visual Basic programs. In a form, a programmer can create objects in a form.
Introduction To Visual Basic 6. Announcements  Thursday, Oct 9th, 7:30PM, C106 Lloyd Douglas (NSF) Diversity in Science-Who needs it? 5 extra credits.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Word Project 8 Working with Macros and Visual Basic for Applications (VBA)
Chapter 2 –Visual Basic, Controls, and Events
Adding Controls to User Forms. Adding Controls A user form isn’t much use without some controls We’re going to add controls and write code for them Note.
Database Management Review for Final (Part 1) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 15, Wednesday 4/30/2003)
Visual Basic Chapter 1 Mr. Wangler.
05/09/ Introducing Visual Basic Sequence Programming.
Hello World In C++ and Microsoft Visual C++. Directions to begin a project 1. Go to All Programs 2. Open Visual Studio C++ 3. Click on New Project 4.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
Teacher: Ms. Olifer MICROSOFT VISUAL STUDIO 2010: PROPERTIES OF WINDOWS FORM OBJECT.
Chapter 4: The Selection Process in Visual Basic.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 2 Creating a User Interface.
Chapter 2 - More Controls More controls – Text boxes - used for user input – Frames - containers to group items – check boxes - user select an option -
Irwin/McGraw-Hill © The McGraw-Hill Companies, Inc., Visual Basic Projects Project Structure and VB’s Programming Tools chapter TWO.
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Chapter Two Designing Applications Programming with Microsoft Visual Basic th Edition.
Chapter Two Creating a First Project in Visual Basic.
CC111 Lec7 : Visual Basic 1 Visual Basic(1) Lecture 7.
Chapter 2 P. 1 Introducing more controls (on the Toolbox) (Fig. 2.1) - Text box - Frame - Option button - Check box - Image Example P. 44 Figure 2.2 Message.
Chapter 2 - VB 2008 by Schneider1 Chapter 2 –Visual Basic, Controls, and Events 2.1 An Introduction to Visual Basic 2.2 Visual Basic Controls 2.3 Visual.
Managing Controls Lab 2 2 All Rgihs ReservedIsmail M. Romi – PPu: IT DEpt.
Chapter 2 – Introduction to the Visual Studio .NET IDE
3.9 to  Also refer to as Program  Contains set of instructions that tells the computer how to perform specific task.  Each line of code is referred.
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.
Integrated Development Environment Visual Basic IDE Slide 2 of 10 Topic & Structure of the lesson Introduction Integrated Development Environment Tool.
1 Visual Basic Part I - A tool for customizing your program Principles of GIS
CMPF114 Computer Literacy Chapter 3 The Visual Basic Environment 1.
1 Introduction to Visual Basic Dr Mohd Nabil Almunawar MS 3403 Advanced Computing.
BBT 10 Visual Basic 03 Enrichment. Tip Before creating any files for your project, first create a new folder Save all of your files in the folder Pieces.
Word Processor Version.01 EME 4411 Week 5. The Scroll Bars.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 3 Building an Application in the Visual Basic.NET Environment.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Chapter 2 - VB 2008 by Schneider1 Chapter 2 –Visual Basic, Controls, and Events 2.1 An Introduction to Visual Basic 2.2 Visual Basic Controls 2.3 Visual.
Programming with Microsoft Visual Basic 2012 Chapter 1: An Introduction to Visual Basic 2012.
Introduction To Visual Basic 6
Chapter 1: An Introduction to Visual Basic 2015
Introduction to Computer CC111
Introduction to Computing
Chapter 2 – Introduction to the Visual Studio .NET IDE
3.01 Apply Controls Associated With Visual Studio Form
1. Introduction to Visual Basic
3.01 Apply Controls Associated With Visual Studio Form
Chapter 3 Fundamentals of Programming in Visual Basic 3
Please use speaker notes for additional information!
Project Design, Forms and Buttons
Introduction to Programming
Chapter 4 Enhancing the Graphical User Interface
Presentation transcript:

VB Objects & Events (Exercises) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 3, Friday 1/31/2003)

2 Objects (Controls) Pointer Label Frame Check Box Combo Box Horizontal Scroll Bar Timer Directory List Box Shapes Image Box Object Linking Embedding Picture Box Text Box Command Button Option Button List Box Vertical Scroll Bar Drive List Box File List Box Lines Data Tool The Toolbox Command buttons Text box Picture box Label

3 Objects and Event [Sub]procedures Name: cmdExit Caption: &Exit Name: cmdFontSize Caption: Change Font &Size Private Sub cmdFontSize_Click() txtName.Font.Size = 18 End Sub Event procedure Private Sub cmdBold_Click() txtName.Font.Bold = True End Sub Event procedure Private Sub cmdExit_Click() End End Sub Event procedure

4 Event [Sub]procedures’ syntax [Private | Public] Sub ProcedureName_Event ( ) Statements End Sub Where: Public means that the Subprocedure is accessible to all other procedures in the application Private means that the Subprocedure is only accessible to all other procedures related to the form ProcedureName is usually the name of the object associated to an event Event is the name of the event that might happen Statements are the instructions to be executed at run time

5 Statements n All statements on slide # 3 are Assignment statements n Assignment statements assign values to Objects’ properties Example txtName.Font.Size = 18 Object Property Assigned value

6 Assignment Statements syntax ObjectName.Property[.SubProperty] = Value Where: ObjectName is the name of the object which property will be assigned a value. Property is the object’s property which value will be assigned SubProperty: In some case, properties may have subproperties. Subproperty refer to a particular subproperty. Value. Also refered to as Setting, Value is the value to be assigned to the property.

7 Object, Properties, Events n Each object has its related: – Properties (characteristics like name, color, size, etc.) – Events (actions it respond to) n Different Properties and Events for objects – But all objects have the Name property n Should know common properties and common events for usual objects

8 Common properties & events Object: Command button Common Properties - Caption (Text that appear on the button) - BackColor (Color of the background) - Default (True or False) - Enabled (Can respond to User events: True or False) - Font (Font.Name, Font.Size, Font.Bold, Font.Italic..) - Visible ( Make object appear or disappear: True or False ) Common Events - Click - GotFocus - LostFocus

9 Common properties & events Object: Text box Common Properties - Alignment (0-Left, 1-Right, 2-Center) - BackColor (Color of the background) - BorderStyle (Style of the border: 0 or 1) - Enabled (Can respond to User events: True or False) - Font (Font.Name, Font.Size, Font.Bold, Font.Italic..) - ForeColor (Color of the foreground) - Text (Text to be displayed) - Visible ( Make object appear or disappear: True or False ) Common Events - GotFocus - Change - KeyPress - LostFocus - Click - KeyUp

10 Common properties & events Object: Picture box Common Properties - BackColor (Color of the background) - BorderStyle (Style of the border: 0 or 1) - Enabled (Can respond to User events: True or False) - ForeColor (Color of the foreground) - Picture (specification of a file) - Visible ( Make object appear or disappear: True or False ) Common Events - GotFocus, LostFocus, Change, Click, DblClick Common Methods: - Print - Cls

11 Common properties & events Object: Label Common Properties - Alignment (0-Left, 1-Right, 2-Center) - Caption (Text that appear on the button) - BackColor (Color of the background) - BorderStyle (Style of the border: 0 or 1) - Font (Font.Name, Font.Size, Font.Bold, Font.Italic..) Common Events Note: We usually don’t associate events procedures to Labels even if it is possible to do so.

12 Setting colors n At design time – Colors are selected from the palette (in Properties Win.) n When writing code – 8 most common colors can be assigned with the following color constants: vbBlackvbRedvbGreenvbYellow vbBluevbMagnetavbCyanvbWhite Examples: txtName.ForeColor = vbGreen picOutput.BackColor = vbWhite

13 Assigning Font settings n At design time – Font settings are assigned from the Properties window n When writing code – Font settings can be assigned using statements like: txtBox.Font.Size = 18 lblOne.Font.Italic = True txtBox.Font.Name = “Courier” txtBox.Font.Underline = True

14 Exercises 19-32, page 68 Write a line (or lines) of code to carry out the following: n Display " The stuff that dreams are made of. " in red letters in txtBox Answer: n Display " Life is like a box of chocolates. " in Courier font in txtBox Answer:

15 Exercises n Delete the content of txtBox Answer: n Delete the content of lblTwo Answer:

16 Exercises n Make lblTwo disappear Answer: n Remove the border from lblTwo Answer: n Give picBox a blue background Answer:

17 Exercises n Place a bold red "Hello" in lblTwo Answer:

18 Exercises n Place a bold italic "Hello" in txtBox Answer: n Make picBox disappear Answer:

19 Exercises n Give the focus to cmdButtom Answer: n Remove the border from picBox Answer:

20 Exercises n Place a border around lblTwo and center its content Answer: n Give the focus to txtBoxTwo Answer:

21 Problem 1 n Consider the following interface and property settings Object Property Setting frmEx1 Caption Colorful Text lblBack Caption Background cmdRed Caption &Red cmdBlue Caption &Blue txtShow Text Beautiful Day Multiline True Alignment 2 –Center lblFore Caption Foreground cmdWhite Caption &White cmdYellow Caption &Yellow Write the code to carry out the following task: Pressing the command buttons alter the background and foreground colors in the textbox.

22 Problem 2 n Consider the following interface and property settings Object Property Setting frmEx2 Caption Sayings txtQuote Text [Blank] txtLife Text Life txtFuture Text Future txtTruth Text Truth Write the code to carry out the following task: When you click on one of the three small text boxes at the bottom of the form, an appropriate saying is displayed in the large text box. Use the sayings “I like life, it’s something to do.”; “The future isn’t what it used to be”; and “Tell the truth and run”.

23 Problem 3 n Consider the following interface and property settings Object Property Setting frmEx3 Caption Fonts txtShow Text [Blank] cmdCour Caption Courier cmdSerif Caption MS Serif cmdWing Caption Wingdings Write the code to carry out the following task: After the user type something into the text box, the user can change the font by clicking on one of the command buttons.

Other Exercise (To do later)

25 Problem 4: Payroll problem 2 Based on the Program Flowchart and the Pseudocode that follow (see next two slides), create the Visual Basic application for the following payroll problem: Compute the pay for an employee, assuming that name, Social Security Number, hours worked, and hourly rate are input. The output will be the name, Social Security Number, and pay of the employee. Regular pay will be computed as hours (up through 40) times rates, and overtime pay will be computed at time and half (1.5 times hours times rate) for all the hours worked over 40.

26 Problem 4 ( Program Flowchart ) READ NAME, SSN, HOURS, RATE WRITE NAME, SSN, PAY HOURS > 40 ? PAY = REGPAY + OTPAY PAY = HOURS * RATE START STOP YES NO OTPAY = (HOUR – 40) * (1.5 * RATE) REGPAY = 40 * RATE

27 Problem 4 ( Pseudocode ) Start Read NAME, SSN, HOURS, RATE IF HOURS > 40 THEN REGPAY = 40 * RATE OTPAY = (HOURS – 40) * (1.5 * RATE) PAY = REGPAY + OTPAY ELSE PAY = HOURS * RATE ENDIF Write NAME, SSN, PAY Stop

28 Problem 4 (VB solution)