CS0004: Introduction to Programming

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

CS0004: Introduction to Programming Select Case Statements and Selection Input.
Sub and Function Procedures
Lecture Set 4 Data Types and Variables Part B – Variables, Constants, Expressions Conversion Rules Options Strict, Option Explicit Scope of Definition.
1 Programmer-Defined Functions Functions allow program modularization Variables declared in function are local variables Only known inside function in.
1 CS 106, Winter 2009 Class 10, Section 4 Slides by: Dr. Cynthia A. Brown, Instructor section 4: Dr. Herbert G. Mayer,
1 CS 106, Winter 2009 Class 11, Section 4 Slides by: Dr. Cynthia A. Brown, Instructor section 4: Dr. Herbert G. Mayer,
An Introduction to Programming with C++ Fifth Edition
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Example 2.
Sub Programs To Solve a Problem, First Make It Simpler.
Chapter 4 - VB.Net by Schneider1 Chapter 4 General Procedures 4.1 Sub Procedures, Part I 4.2 Sub Procedures, Part II 4.3 Function Procedures 4.4 Modular.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Functions Part I.
Introduction to Methods
Lesson15. JavaScript Objects Objects encapsulate data (properties) and behavior(methods); the properties and the methods of an object are tied together.
Day 4 Objectives Constructors Wrapper Classes Operators Java Control Statements Practice the language.
Apply Sub Procedures/Methods and User Defined Functions
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
CS0004: Introduction to Programming Variables – Numbers.
CS0004: Introduction to Programming Relational Operators, Logical Operators, and If Statements.
Why to Create a Procedure
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
CS0004: Introduction to Programming Variables – Strings.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Functions.
CS0004: Introduction to Programming Subprocedures and Modular Design.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
1 Chapter 5 - General Procedures 5.1 Function Procedures 5.2 Sub Procedures, Part I 5.3 Sub Procedures, Part II 5.4 Modular Design.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Functions.
Chapter 6 Sub Procedures
IMS 3253: Subroutines 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Procedures Subroutines Parameters –By Value.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
Python Functions.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 10: Chapter 6: Slide 1 Unit 10 Sub Procedures and Functions Chapter 6 Sub.
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
JavaScript, Fourth Edition
Chapter 3 w Variables, constants, and calculations DIM statements - declaration temporary memory locations identifier, data type, scope data types - values.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
1 Functions, Part 1 of 2 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function Header Comments.
FUNCTIONS. Topics Introduction to Functions Defining and Calling a Void Function Designing a Program to Use Functions Local Variables Passing Arguments.
Created by Alia Al-Abdulkarim 2008 Visual Basic Vs. Java.
1 ICS103 Programming in C Lecture 8: Functions I.
Week Procedures And Functions 7 A procedure is a collection of statements that performs a task.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Review Expressions and operators Iteration – while-loop – for-loop.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 6 Sub Procedures And Functions.
Copyright © 2014 Pearson Education, Inc. Chapter 6 Procedures and Functions.
Sub Procedures and Functions Visual Basic. Sub Procedures Slide 2 of 26 Topic & Structure of the lesson Introduction to Modular Design Concepts Write.
Sub Procedures And Functions
Programming Right from the Start with Visual Basic .NET 1/e
Chapter 9: Value-Returning Functions
Topics Introduction to Functions Defining and Calling a Void Function
COMPUTATIONAL CONSTRUCTS
JavaScript: Functions
Method.
Chapter 4 - Visual Basic Schneider
Chapter 6 Sub Procedures
Procedures and Functions
PHP.
Introduction to Visual Programming
Topics Introduction to Functions Defining and Calling a Void Function
Tonga Institute of Higher Education
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Chapter 6 – Methods Topics are:
Topics Introduction to Functions Defining and Calling a Function
CodePainter Revolution Trainer Course
Javascript Chapter 19 and 20 5/3/2019.
Methods/Functions.
Functions, Part 1 of 2 Topics Using Predefined Functions
Presentation transcript:

CS0004: Introduction to Programming Function Procedures

Review General Form of an If/Else Block… If condition Then some code some other code End If General Form of a Select Case Block Select Case selector Case valueList1 action1 Case valueList2 action2 Case Else actionOfLastResort End Select

Review A value list can be a…(4 things) Literal Variable Expression Range What property holds whether a radio button or check box is checked? Checked

Function Procedures Functions are used in programming to break complex problems into smaller ones We have encountered built-in functions in VB before Int(param1) FormatNumber(param1,param2) These functions output a value to where they are used. When a function outputs a value, it is said to return a value. When a function is used, it is said to be called. You can pass input to a function by supplying it with arguments. Arguments are the values you pass to a function Parameters are the local variables used in the function definition.

Function Procedures We can define our own functions: General Form: Function FunctionName (ByVal var1 As Type, ByVal var2 As Type) As ReturnDataType … some code Return expression End Function FunctionName is the name of the function var1 and var2 are the names of the parameters The Types following var1 and var2 tell what type the parameters are ReturnDataType is the type of the value that the function returns The expression in Return expression is what value is returned by the function.

Function Example 1 New Topics: Programmer Defined Function Parameters/arguments Return Statement Function Call

Function Procedures Notes: The code for the function is called the function definition. When calling a function, you must supply it with the same number of arguments as parameters defined in the function definition. You can create functions with no parameters. Just leave the parentheses empty when defining the function. A function MUST return a value. Function names in VB: Typically are camel case with first letter capitalized. Follow the same naming rules as variables Should be a verb that describe what the function does

Function Example 2 New Topics: Multiple Parameters/Arguments

Scope Scope refers to where a variable can be used (seen). Scope is usually defined by where it was declared. A variable declared in a function or event procedure can ONLY be used in the function or event procedure where it was declared. A variable declared inside of a class, but not in any of its procedures can be used anywhere in the class, including in any of its procedures. Parameters can be used ONLY in the function they belong to.

Scope Example: Public Class frmMain Dim var1 As Integer Function someFunction(ByVal x As Double, ByVal y As Double) As Double Dim var2 As String … End Function Function otherFunction(ByVal x As String, ByVal y As String) As Double Dim var3 As String End Class

Function Documentation You should document EVERY function you write: ‘ Function Name: The name of the function ‘ Returns: Return type and brief description of what it ‘ is ‘ Parameters: Types and brief descriptions of what they are ‘ Description: Brief description of what the function does