Types and Loops.

Slides:



Advertisements
Similar presentations
Java Control Statements
Advertisements

Integrated Business Applications with Databases (D3) Jenny Pedler
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Object Oriented Programming A programming concept which views programs as objects with properties and ways to manipulate the object and the properties.
Some computer fundamentals and jargon Memory: Basic element is a bit – value = 0 or 1 Collection of “n” bits is a “byte” Collection of several bytes is.
AE6382 VBA - Excel l VBA is Visual Basic for Applications l The goal is to demonstrate how VBA can be used to leverage the power of Excel u VBA syntax.
VBA Modules, Functions, Variables, and Constants
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
Do Loops A Do..Loop terminates based on a condition that is specified Execution of a Do..Loop continues while a condition is True or until a condition.
Program Design and Development
Loops – While, Do, For Repetition Statements Introduction to Arrays
Developing Software Applications Introduction to Programming Fundamentals Scoping in VB Simple Ifs in VB.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
CS 106 Introduction to Computer Science I 02 / 20 / 2008 Instructor: Michael Eckmann.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Slide 1 Variables, Constants and Data Types. Slide 2 Variables v Three components define a variable: –Name (memory location) –Type –Information (value)
Modeling using VBA. Using Toolbox This is a label This is a button Using the Toolbox select a GUI element and by mouse-click place it on the frame This.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
Data Types and Operations Programming Fundamentals (Writing Code)Programming Fundamentals (Writing Code)
VB Code Statements 3 types of VB statement The Remark statement, known as comments, are used for project documentation only Begin with an apostrophe Not.
VBA & Excel Barry L. Nelson IEMS 465 Fall Quarter 2003.
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.
Day 4 Objectives Constructors Wrapper Classes Operators Java Control Statements Practice the language.
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
Lecture Set 5 Control Structures Part D - Repetition with Loops.
Microsoft Access Using Visual Basic Routines. Visual Basic Datatypes Boolean Byte Currency Date Double Integer Long Object Single String Variant Hyperlink.
National Diploma Unit 4 Introduction to Software Development Data types, variables and constants.
情報基礎 B Lecture 8 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
Access VBA Programming for Beginners - Class 2 - by Patrick Lasu
What is an Array? An array is a collection of variables. Arrays have three important properties: –group of related items(for example, temperature for.
1 Flow Control II Code: Select-Case and For-Next Controls: Frames and OptionButtons.
Variables,Constants and Data types Variables temporarily stores values during the execution of an application Variables have a name and data type Declare.
Copyright © 2012 Pearson Education, Inc. Chapter 6 More Conditionals and Loops Java Software Solutions Foundations of Program Design Seventh Edition John.
Visual Basic Programming
Lab 4 Range Review, Control Logic and Loops ► Range Review ► Control Logic and Loops ► Exercise.
ME 142 Engineering Computation I Using Subroutines Effectively.
Other Variable Types Dim lab as String makes a box that can store a label tag Dim ColHead As String ColHead = “function” ColHead function Dim lab as Boolean.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Pay Example (PFirst98) Please use speaker notes for additional information!
ME 142 Engineering Computation I Using Subroutines Effectively.
# 1# 1 What is a variable that you create? What is a constant that you create? What is an intrinsic (built-in) constant? What variables are built in?
Hungarian Notation A must in this course Every object used MUST be renamed including the form(s) using the following rules Form  frmFormName E.g. frmTemperature.
1 Arrays of Arrays An array can represent a collection of any type of object - including other arrays! The world is filled with examples Monthly magazine:
Introduction to Programming Lecture 2 Msury Mahunnah, Department of Informatics, Tallinn University of Technology.
Visual Basic Objects / Properties / Methods PropertyAdjective ObjectNoun Part of the application Attribute MethodVerb Action to do something.
CECS 5020 Computers in Education Visual Basic Variables and Constants.
Higher Computing Software Development -So Far- 5/10/10.
CS-1010 Dr. Mark L. Hornick 1 Selection and Iteration and conditional expressions.
Expressions and Order of Operations Operators – There are the standard operators: add, subtract, divide, multiply – Note that * means multiply? (No times.
CIS 338: VB Variables Dr. Ralph D. Westfall April, 2011.
Pseudocode Skill Area Materials Prepared by Dhimas Ruswanto, BMm.
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
More Visual Basic Code: if-then-else, for loops Controls: Multiple forms, List Boxes, Radio buttons, frames,
Introduction to Programming Lecture 2
VBScript Session 1 Dani Vainstein.
VBA - Excel VBA is Visual Basic for Applications
VBA - Excel VBA is Visual Basic for Applications
VBScript Session 1 IT Professional Academy.
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Visual Basic 6 (VB6) Data Types, And Operators
2. Java language basics (2)
2. Understanding VB Variables
The switch Statement The switch statement provides another way to decide which statement to execute next The switch statement evaluates an expression,
Module 4 Loops.
Fundamentals of visual basic
The structure of programming
VBScript Session 1.
Presentation transcript:

Types and Loops

Short List of VBA Types Data Type Range Byte 0 to 255 Boolean True or False Integer -32678 to 32678 Long(integer) -2147,483,648 to 2147,483,648 Single(floating) 1.4 E-45 to 3.4 E 38 digits for Positive Values Double (floating) 4.9 E -324 to 1.79 E 208 for positive values String (Variable Length) 0 to approximately 2 billion String (Fixed Length) 0 to approximately 65,400 Variant (with Numbers) Any Numeric value upto length of double Variant (with Characters) Same as String variable length

Option Explicit If you don’t declare the data type for a variable that you use in a VBA routine, VBA uses the default data type “VARIANT”. DATA stored as a variant acts like a CHAMELON, it changes type depending on what you do with it.

Public and Private Function Public (Optional) indicates that the function procedure is accessible to all other procedures in all other modules in all active excel VBA Projects Private: Indicates that the function procedure is accessible only to other procedures in the same module

Variables Public Variables To make a variable available to all procedures in all VBA modules in a project Public SomeRate as long (declared outside of function) Private Variables Local Variable is a variable declared within a procedure. Local variables can be used only in the procedure in which they are declared. When the procedure ends, the variables no longer exists. Ex: Dim

Loops For Loop : used mainly for loops where the number of times the action is repeated is known in advance Function ForDemol(N As Integer) As Long Dim i As Integer Dim j As Long If N <= 1 Then ForDemol = 1 Else j = 1 For i = 1 To N Step 1 j = j * i Next i ForDemol = j End If End Function

Loops A top-checking loop: The loop condition is checked before anything else gets done. The something to be done can be left undone if the condition is not fulfilled on entry to the loop. A bottom-checking loop: The loop condition is checked after the something to be done is done. The something to be done will always be done at least once.

LOOPS A top-checking loop: Do while <condition> Your Statements Do until <condition> Loop A Bottom-checking loop: Do Your Statements Loop while <condition> Do Loop Until <condition>

Top Checking Loops Top Checking Loops: Do While - Loop Function DoWhileDemo(N As Integer) As Integer Dim i, j As Integer If N < 2 Then DoWhileDemo = 1 Else i = 1 j = 1 Do While i <= N j = j * i i = i + 1 Loop DoWhileDemo = j End If End Function

Top Checking Loops Top Checking Loops: Do Until - Loop Function DoUntilDemo(N As Integer) As Integer Dim i, j As Integer If N < 2 Then DoUntilDemo = 1 Else i = 1 j = 1 Do Until i > N j = j * i i = i + 1 Loop DoUntilDemo = j End If End Function

Bottom Checking Loops Do Loop While < Condition> Function DoLoopWhileDemo(n As Integer) Dim i As Integer Dim j As Long If n < 2 Then DoLoopWhileDemo = 1 Else i = 1 j = 1 Do j = j * i i = i + 1 Loop While i <= n DoLoopWhileDemo = j End If End Function

Bottom Checking Loops Function DoLoopUntilDemo(n As Integer) Dim i As Integer Dim j As Long If n < 2 Then DoLoopUntilDemo = 1 Else i = 1 j = 1 Do j = j * i i = i + 1 Loop Until i > n DoLoopUntilDemo = j End If End Function

Can you write a Function to Compute Implied Volatility Start with a high value Start with a low value Let high =1 Let low =0 We have stock price, strike price, interest rate, time to expiry and Traded_Call_price (Let us call it Target ) Objective to compute Implied Volatility (sigma).

Plug in the average value of (Implied) volatility (sigma) (high +low)/2, and check whether the call price is greater or less than target ( traded option price) if greater then reduce the high to the average value(average of high and low). If less than increase the low to the average value (average of high and low)

We have to check this condition as long as say the difference between high and low is small. We need to repeat the process or put it in a loop. Put the above condition in a loop such that you come out as soon as the difference between high and low is small We will repeatedly test the above condition as long as (High –low) is let say as small as .0001.