CSCI 3327 Visual Basic Chapter 6: More Examples of Methods UTPA – Fall 2011.

Slides:



Advertisements
Similar presentations
Sub and Function Procedures
Advertisements

Pemrograman VisualMinggu …6… Page 1 MINGGU Ke Enam Pemrograman Visual Pokok Bahasan: Module, Class & Methods Tujuan Instruksional Khusus: Mahasiswa dapat.
Murach’s Visual Basic 2008, C4© 2008, Mike Murach & Associates, Inc. Slide 1.
Chapter 3: Using Variables and Constants Programming with Microsoft Visual Basic 2005, Third Edition.
Lecture Set 4 Data Types and Variables Part B – Variables, Constants, Expressions Conversion Rules Options Strict, Option Explicit Scope of Definition.
 2009 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
Math class methods & User defined methods Introduction to Computers and Programming in JAVA: V
CVEV 118/698 Visual Basic Lecture 1 Prof. Mounir Mabsout Expert 1: Elsa Sulukdjian Expert 2: Walid El Asmar.
IS437: Fall 2004 Instructor: Dr. Boris Jukic Data Types, Constants, Variables, Scope, Conversion.
Review for Midterm 2 Nested loops & Math class methods & User defined methods.
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter Three Using Variables and Constants Programming with Microsoft Visual Basic th Edition.
110-D1 Variables, Constants and Calculations(1) Chapter 3: we are familiar with VB IDE (building a form…) to make our applications more powerful, we need.
Apply Sub Procedures/Methods and User Defined Functions
Chapter 3: Using Variables and Constants
Programming with Microsoft Visual Basic th Edition CHAPTER THREE USING VARIABLES AND CONSTANTS.
Methods Chapter 6. 2 Program Modules in Java What we call "functions" in C++ are called "methods" in Java Purpose Reuse code Modularize the program This.
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
Why to Create a Procedure
CSCI 3327 Visual Basic Chapter 6: Methods: A Deeper Look UTPA – Fall 2011.
Language Elements 1. Data Types 2 Floating Point (real) Single Precision Double Precision Decimal Fixed Point (integer) Byte Short Integer Long Numerical.
Lecture 8 Visual Basic (2).
6.1 Introduction Divide and Conquer –The best way to develop and maintain a large program is to construct it from small, manageable pieces. BZUPAGES.COM.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Fund Raiser Application Introducing Scope, Pass-by-Reference and Option Strict.
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 4 Working with Variables, Constants, Data Types, and Expressions.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
 2005 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
CSCI 3327 Visual Basic Chapter 9: Object-Oriented Programming: Classes and Objects UTPA – Fall 2011.
Chapters 2 & 3. .NET Software development model that allows applications created in disparate programming languages to communicate Universal data access.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Chapter 3 w Variables, constants, and calculations DIM statements - declaration temporary memory locations identifier, data type, scope data types - values.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Three Using Variables and Constants.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 15 – Fund Raiser Application Introducing.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Programming with Microsoft Visual Basic th Edition
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Craps Game Application Introducing Random-Number Generation and Enum.
Object-Based Programming in VB.NET. Must Understand Following: Encapsulation Information hiding Abstract Data Type Class, Instance, Reference Variable.
Review for Nested loops & Math class methods & User defined methods.
Murach, Chapter 4. Two Data Types Value Types – Store their own data Reference Types Do not store their own data Stores a reference to an area of memory.
110 E-1 Variables, Constants and Calculations(2) Chapter 3: Operations on variables, scope of a variable, formatting data Doing Arithmetic.
 Static  Example for Static Field  Example for Static Method  Math class methods  Casting  Scope of Declaration  Method Overloading  Constructor.
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
CIS 338: VB Variables Dr. Ralph D. Westfall April, 2011.
Object-Oriented Programming: Classes and Objects Chapter 1 1.
Programming with Microsoft Visual Basic 2012 Chapter 3: Using Variables and Constants.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Data Types. Visual Basic provides data type Single for storing single-precision floating-point numbers. Data type Double requires more memory to store.
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
Chapter 2 Objects and Classes
A variable is a name for a value stored in memory.
Object-Oriented Programming: Classes and Objects
An Application Uses Variables to Hold Information So It May Be Manipulated, Used to Manipulate Other Information, or Remembered for Later Use.
Methods Chapter 6.
Data Types, Arithmetic Operations
Chapter 3: Using Variables and Constants
Object-Oriented Programming: Classes and Objects
Lecture Set 4 Data Types and Variables
Advanced Programming Chapter 7: Methods: A Deeper Look
Classes & Objects: Examples
CIS16 Application Development Programming with Visual Basic
The University of Texas Rio Grande Valley
CSCI 3328 Object Oriented Programming in C# Chapter 3: Introduction to Classes and Objects – Exercises UTPA – Fall 2012 This set of slides is revised.
The University of Texas – Pan American
CSCI 3327 Visual Basic Chapter 6: Methods: A Deeper Look
Methods.
Chapter 8 - Functions and Functionality
Presentation transcript:

CSCI 3327 Visual Basic Chapter 6: More Examples of Methods UTPA – Fall 2011

Objectives In this chapter, you will: –See more examples about methods Subroutines Functions –Learn the implicit/explicit argument conversions –Become aware of the scope of the declaration –Get familiar with the Random class/object to generate random numbers 2

Example 6.3: WageCalculator.vb URL: – p_2010/codeexamples.htmlhttp://media.pearsoncmg.com/ph/esm/deitel/vb_ht p_2010/codeexamples.html Subroutine: –Method that does not return a value Sub methodName (parameter-list): method header Method body – block Keyword Const: Declares a constant 3

Example 6.4: WageCalculator.vb URL: – p_2010/codeexamples.htmlhttp://media.pearsoncmg.com/ph/esm/deitel/vb_ht p_2010/codeexamples.html Function –Method that returns a value Function methodName(parameter-list) As return-type Return statement: Return variable 4

Implicit Argument Conversions Widening conversion –An argument is converted to a parameter of another data type that can hold more data Narrowing conversion –Opposite –Potential data loss during the conversion 5

Examples of Implicit Conversion Examples –Char  String –Integer  Decimal or Double –Decimal  Integer –resultLabel.Text = Math.Sqrt(4) 6

Option Strict and Data-Type Conversions Visual Studio –2010: Tools  Options  Projects and Solutions  VB defaults –2008: Project  Properties  Compile 7

8

Option Strict and Data-Type Conversions (cont'd) Option Explicit –On by default – declare all variables before they are used Option Strict –Off by default –On – requires performing explicit conversions by cast operator 9

Option Strict and Data-Type Conversions (cont'd) Option Infer –On by default – complier infers a variable’s type based on its initializer value Dim x = 7 ' compiler infers: x is Integer type 10

Explicit Conversion Explicit conversion –Class Convert Convert.ToInt32 (…) Convert.ToDouble (…) Convert.ToDecimal (…) Convert.ToString (…) 11

The Scope of Declarations Block scope –A variable declared in the body of a control statement –E.g., If … Then Method scope –A variable declared in a method Class scope –A member declared in the class’s body, but outside the bodies of the class’s methods 12

Example 6.9: FundRaiser.vb URL: – 10/codeexamples.htmlhttp://media.pearsoncmg.com/ph/esm/deitel/vb_htp_20 10/codeexamples.html Donation –17% of the donation is used for covering operating expenses –Calculate the donation after expenses and the total raised –Instance variable, totalRaised: class scope –Local variables in method donateButton_Click: method scope 13

Random Class/Object Random Object, class Random –Dim randomObject As New Random() –Dim randomNumber As Integer = randomObject.Next() randomNumber is within [0, Int32.MaxValue) –Dim Val As Integer = 1 + randomObject.Next(6) Val is within [1, 6] –Dim Val As Integer = randomObject.Next(1, 7) Val is within [1, 6] 14

Example 6.11: RollDice.vb URL: – odeexamples.htmlhttp://media.pearsoncmg.com/ph/esm/deitel/vb_htp_2010/c odeexamples.html Rules: –First throw: 7, 11 – win; 2, 3, 12 – lose; 4, 5, 6, 8, 9, 10 – player's points –Afterwards, 7 – lose; make their points – win Controls –Button rollButton.Enabled = False –PictureBox pointDie1PictureBox.Image = Nothing 15