Loops, Subs, & Functions Stefano Grazioli.

Slides:



Advertisements
Similar presentations
Sep-05 Slide:1 VBA in Excel Walter Milner. Sep-05 Slide:2 VBA in Excel Introduction VBA = Visual Basic for Applications Enables end-user programming In.
Advertisements

Excel and Visual Basic. Outline Data exchange between Excel and Visual Basic. Programming VB in Excel.
Tutorial 12: Enhancing Excel with Visual Basic for Applications
Chapter 7: User-Defined Functions II
Microsoft Access Course 1. Introduction to the user interface.
Control Structures: Part 2. Introduction Essentials of Counter-Controlled Repetition For / Next Repetition Structure Examples Using the For / Next Structure.
Visual Basic: An Object Oriented Approach 4: Simple Programming in VB.
Promoting Code Reuse Often in programming, multiple procedures will perform the same operation IN OTHER WORDS – the same piece of code will do the same.
VBA & Excel Barry L. Nelson IEMS 465 Fall Quarter 2003.
Financial Information Management Stefano Grazioli.
Financial Information Management Managing Financial Information Critical Thinking Business Process Modeling WINIT Control Structures Homework.
 Excel – Basic Elements  Using Macros  Excel VBA Basics  Excel VBA Advanced.
IE 212: Computational Methods for Industrial Engineering
VBA for Excel. What is a spreadsheet? u An Excel spreadsheet is a set of worksheets  Each worksheets is made up of rows and columns of cells  Rows are.
Programming Test #1 Solutions. Multiple Choice 1. B) the grammar of the coding language 2. C) String 3. A) Single 4. C) 2Burgers4Me 5. B) Design Time.
Chapter 9: Writing Procedures Visual Basic.NET Programming: From Problem Analysis to Program Design.
MS Excel Introduction to Excel; What Can I Do with a Spreadsheet? Unit 5.
Week 4.  Recap – Ranges  For Each Loops  Ranges Referencing Range Objects  Set (keyword)
CS285 Visual Basic 2 Department of Computing UniS 1 Statements in Visual Basic A statement is the fundamental syntactical element of a program smallest.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Chapter 16: Programming Structures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Lab 4 Range Review, Control Logic and Loops ► Range Review ► Control Logic and Loops ► Exercise.
A lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. a lesson approach Microsoft® Excel 2010 © 2011 The McGraw-Hill Companies,
Counter-Controlled Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
6.2 For…Next Loops General Form of a For…Next Loop
CS Class 08 Today  Exercises  Nested loops  for statement  Built-in functions Announcements  Homework #3, group solution to in-class.
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
Chapter 16: Programming Structures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
JavaScript, Fourth Edition
ME 142 Engineering Computation I Using Subroutines Effectively.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 10 - JavaScript/JScript: Control Structures II Outline 10.1Introduction 10.2Essentials of.
1. FINISHING FUNCTIONS 2. INTRODUCING PLOTTING 1.
VAT Calculator program Controls Properties Code Results.
ME 142 Engineering Computation I Using Subroutines Effectively.
Created by Alia Al-Abdulkarim 2008 Visual Basic Vs. Java.
Visual Basic Objects / Properties / Methods PropertyAdjective ObjectNoun Part of the application Attribute MethodVerb Action to do something.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
Financial Information Management VB, VBA, VS, VSTO & VBE: Putting it all together Source: Excel VBA Programming by John Walkenbach.
© Stefano Grazioli - Ask for permission for using/quoting: Source: Excel VBA Programming by John Walkenbach.
Lab 5 Arrays ► Lab 4 Exercise Review ► Array Concept ► Why Arrays? ► Array Declaration ► An Example of Array ► Exercise.
COMPREHENSIVE Excel Tutorial 12 Expanding Excel with Visual Basic for Applications.
CHAPTER #7 Problem Solving with Loop. Overview Loop logical structure Incrementing Accumulating WHILE/WHILE-END FOR Nested loop Pointer Algorithmic instruction.
© Stefano Grazioli - Ask for permission for using/quoting: Stefano Grazioli.
Control Structures (part II)
UNIT 5 Lesson 15 Looping.
Chapter 7: Getting Input From Users
Introduction to Programming
Chapter 5- Control Structures: Part 2
Value-Returning Functions
Lesson 16 Sub Procedures Lesson 17 Functions
Control Structures: Part 2
Procedures Stefano Grazioli.
Learning Excel Session 9 and 10 Dr. Chaitali Basu Mukherji.
Control Structures (part II)
Dynamic SQL Queries Stefano Grazioli.
CIS16 Application Development and Programming using Visual Basic.net
Introduction to Programming
Process Automation: From models to code
Loops, Subs, & Functions Stefano Grazioli.
BI and data quality Stefano Grazioli.
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Process Automation: focus on imagination and modeling
Python Basics with Jupyter Notebook
Dynamic SQL Queries Stefano Grazioli.
Dynamic SQL Queries Stefano Grazioli.
BI and data quality Stefano Grazioli.
Process Automation: focus on imagination and modeling
Introduction to Programming
Presentation transcript:

Loops, Subs, & Functions Stefano Grazioli

Critical Thinking Homework folders are automatically created for each homework. Submit during the right time window. EasyMeter 

H5

It begins with figuring out what needs to be done Hey, awesome financial calculator! Can I have the table of results in a choice of colors? User perspective “Use cases” Talk about it Sketch it Show it Prototype with paper and pencil

Activity Diagram (part III) Simple Financial Calculator User inputs principal, years, and interest rate Autofit the columns User presses “print table” button Principal, Year, or Rate is missing Ask the user for a color preference Alert the user Print table header and data a default b i > number of years Format the data Format Table in Red Format Table in Green Format Table in Blue i <= number of years Print the ith row of data

An alternative to IF…THEN when there are multiple options Ask the user for a color preference Select Case textFromUser Case “a” ‘ More instructions… red paint Case “b” ‘ More instructions… green paint Case Else ‘ More instructions… blue paint End Select a b default Format Table in Red Format Table in Green Format Table in Blue

You Do The Talking Name Learning objectives What you like about the class so far What can be improved Attitude towards the Tournament?

Loops

Loops – For … Next For i As Integer = 1 To 10 Step 1 next Range(“A3”).Offset(i, 0).Value = i * 100 ‘ more commands as needed next

Loops – For Each For Each myCell As Excel.Range in Range("A1:B4") myCell.Value = myCell.Value * 2 ‘ more commands as needed Next

Loops – Do Loop #1 ' count columns. numberOfColumns starts = 0 Do While topLeftCell.Offset(0,numberOfColumns).Text <>"" numberOfColumns = numberOfColumns + 1 Loop

Loops – Do Loop #2 Do ‘ body of the loop Loop While <test>

Implementing a nested Loop Increment r by 2 & reset c Increment c by 1 For r As Integer = 1 To (numberOfRows-1) Step 2 For c As Integer = 0 To (numberOfColumns - 1) topLeftCell.Offset(r, c).Interior.Color = Drawing.Color.Pink Next Color the cell (offset r,c) c < (number of columns -1) r < (number of rows -1)

What Is New In Technology? WINIT What Is New In Technology?

Lasagne and Tagliatelle Procedures Lasagne and Tagliatelle

Subs are a type of procedure Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim inputFromUser As Double = 0 Dim square As Double = 0 inputFromUser = InputBox("Please enter a number to square") square = inputFromUser ^ 2 ShowTheUser(square) End Sub Private Sub ShowTheUser(someValue As Double) Range(“A1”).Value = "The result is " + someValue.ToString("N0") A procedure is a named sequence of steps Purpose: reuse & simplify existing code Good practice: shorter than a single screen Sometimes it takes arguments “Macro” is the old name for procedure

Variables and Parameters Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim inputFromUser As Double = 0 Dim square As Double = 0 inputFromUser = InputBox("Please enter a number to square") square = inputFromUser ^ 2 ShowTheUser(square) End Sub Private Sub ShowTheUser(someValue As Double) Range(“A1”).Value = "The result is " + someValue.ToString("N0") Variables have a lifecycle / scope Parameters are a special type of variable: used as input to procedures Find the vars and params in here

Functions are another type of procedure input Return a single value Conceptually similar to the formulas in your worksheets output Private Function CalcInterest(r As Double, principal As Double, t As Double) As Double Dim interest As Double = 0 interest = principal * ((((1 + r) ^ t) - 1)) Return interest End Function

Suggestions None. Doing well.