IE 8580 Module 4: DIY Monte Carlo Simulation

Slides:



Advertisements
Similar presentations
ISOM3230 Business Applications Programming
Advertisements

Visual Basic for Applications. What it does Extends the features and built in functions of Excel – Create and run VB procedures – Some may be easy to.
1.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
30/04/ Selection Nested If structures & Complex Multiple Conditions.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
With Microsoft Excel 2010 © 2011 Pearson Education, Inc. Publishing as Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Excel 2010.
Programming in Visual Basic
String Variables Visual Basic for Applications 4.
Data Types and Operations Programming Fundamentals (Writing Code)Programming Fundamentals (Writing Code)
Adding Automated Functionality to Office Applications.
VBA & Excel Barry L. Nelson IEMS 465 Fall Quarter 2003.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 9 Car Payment Calculator Application Introducing the Do While...Loop and Do Until...Loop.
VBA – Visual Basic for Applications Week 20 - Tutorial.
McGraw-Hill/Irwin Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. Extended Learning Module M Programming in Excel with VBA.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #4: Working with Variables and User Interfaces IE 212: Computational Methods for Industrial Engineering.
© McGraw-Hill Companies, Inc., McGraw-Hill/Irwin Extended Learning Module M Programming in Excel with VBA.
McGraw-Hill/Irwin Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. Extended Learning Module M Programming in Excel with VBA.
Mr C Johnston ICT Teacher BTEC IT Unit 06 - Lesson 05 Learning To Program.
Chapter 4 The If…Then Statement
1 Visual Basic for Applications (VBA) for Excel Prof. Yitzchak Rosenthal.
1 Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops 6.3 List Boxes and Loops.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Interest Calculator Application Introducing the For...Next Repetition Statements.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Microsoft Office Excel Copyright © 2008 Pearson Prentice Hall. All rights reserved
Access VBA Programming for Beginners - Class 2 - by Patrick Lasu
Week 2.  Macros revisited  The VBA Editor  The object model  Using variables  If statements.
Chapter 16: Programming Structures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Lab 4 Range Review, Control Logic and Loops ► Range Review ► Control Logic and Loops ► Exercise.
Applications Development
Chapter 9 Macros And Visual Basic For Applications.
ME 142 Engineering Computation I Using Subroutines Effectively.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 5.1 Test-Driving the Inventory Application.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
Introduction to Excel VBA UNC Charlotte CPE/PDH Series December 17, 2009.
Chapter 3 Control Structures. The If…Then Statement The If…Then statement is a Decision statement = that executes a set of statements when a condition.
ME 142 Engineering Computation I Using Subroutines Effectively.
Chapter 4 Getting Started with VBA. Subroutines Subroutine is the logical section of code that performs a particular task. Subroutine is also called a.
CECS 5020 Computers in Education Visual Basic Variables and Constants.
Controlling Program Flow with Looping Structures
Lab 6 (1) Range Review, Control Logic and Loops ► Control Logic and Loops ► Exercise.
Controlling Program Flow with Decision Structures.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
COMPREHENSIVE Access Tutorial 11 Using and Writing Visual Basic for Applications Code.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Slide 1 Chapter 4 The If…Then Statement  Conditional control structure, also called a decision structure  Executes a set of statements when a condition.
COMPREHENSIVE Excel Tutorial 12 Expanding Excel with Visual Basic for Applications.
The Advantage Series ©2005 The McGraw-Hill Companies, Inc. All rights reserved Chapter 12 Introducing Visual Basic for Applications Microsoft Office Excel.
Welcome to Computer Programming II! Computer Programming II Summer 2015.
© 2006 Lawrenceville Press Slide 1 Chapter 5 The If…Then Statement (One-Way)  Conditional control structure, also called a decision structure  Executes.
Multiple Forms and Menus
IE 8580 Module 4: DIY Monte Carlo Simulation
Outline In this module, the following topics will be covered:
VBA - Excel VBA is Visual Basic for Applications
Chapter 4 The If…Then Statement
Visual Basic 6 (VB6) Data Types, And Operators
3rd prep. – 2nd Term MOE Book Questions.
Microsoft Office Illustrated
3rd prep. – 2nd Term MOE Book Questions.
Final Exam Review Part 4 - VBA
Objectives Learn about Function procedures (functions), Sub procedures (subroutines), and modules Review and modify an existing subroutine in an event.
Control Structures: Part 1
Exploring Microsoft Excel
Chapter (3) - Looping Questions.
Fundamentals of visual basic
Data Types List Box Combo Box Checkbox Option Box Visual Basic 6.0
Additional Topics in VB.NET
CHAPTER FOUR VARIABLES AND CONSTANTS
Lesson 1 - Automating Tasks
Tutorial 11 Using and Writing Visual Basic for Applications Code
Presentation transcript:

IE 8580 Module 4: DIY Monte Carlo Simulation Lecture 4.3: Visual Basic for Applications 102

More detailed steps Add a module Start the sub Project Explorer Highlight the Excel file Insert > Module Start the sub In Code window, type Sub LoopIt <Enter> () and End Sub are added automatically IE 8580, mason@clemson.edu

Write the Following Program Notice the blue for the reserved words IE 8580, mason@clemson.edu

Create a button in Excel Go back to Excel Developer Tab Click Insert Click the button symbol Draw button Assign Macro Dialog Box opens Select the macro we created, click OK Click the button while still selected to change text Unselect the button Click it to run To reselect the button, right click the button then left click IE 8580, mason@clemson.edu

Declaring Variables Declare all variables Use Dim keyword Basic Types Whole Numbers: Integer (-32,768 to 32,768), Long (more than Integer) Real Numbers: Single, Double String, Boolean, Currency, Variant Objects If you try to assign a value out of the allowable range, you will get an OVERFLOW error IE 8580, mason@clemson.edu

Syntax for Declaring Variables Basic syntax Dim varname As type Multiple variables on a line Dim i As Integer, j As Integer, k As Integer Variables get values using the equal sign assignment i = 1 IE 8580, mason@clemson.edu

The ampersand (&) concatenates the information Message Boxes Most basic syntax MsgBox “stuff for the box” MsgBox “the value of the variable is ” & varname The ampersand (&) concatenates the information Be careful with spaces!!! IE 8580, mason@clemson.edu

If condition then do_something Else do_something_else End if Basic If Syntax If condition then do_something If condition then do_something Else do_something_else End if IE 8580, mason@clemson.edu

If condition then do_something Else do_something_else End if Basic If Syntax If condition then do_something If condition then do_something Else do_something_else End if Statements can be multiple lines Indentation helps readability VBA does some indention for you I love tabs IE 8580, mason@clemson.edu

If condition then do_something Else do_something_else End if Basic If Syntax If condition then do_something If condition then do_something Else do_something_else End if The “else” clause is optional IE 8580, mason@clemson.edu

If condition then do_something Else do_something_else End if Basic If Syntax If condition then do_something If condition then do_something Else do_something_else End if The “else” clause is optional IE 8580, mason@clemson.edu

If-then-elseif Constructions If condition1 then do_something1 Elseif condition2 do_something2 Elseif … Else do_default End if IE 8580, mason@clemson.edu

For repeating a statement or series of statement over and over again Looping For repeating a statement or series of statement over and over again Definite (pre-determined) number of repetitions: use a for loop Indefinite number of repetitions: Repeat some code while some condition holds: use one of the four do (or while) loop structures IE 8580, mason@clemson.edu

For counter = first To last [Step increment] statements Next [counter] For Loops first, last and increment are often integers (positive or negative, increment is not 0) Using the counter in the Next statement Helps readability Required for nested for loops For counter = first To last [Step increment] statements Next [counter] IE 8580, mason@clemson.edu

Check If You Are Following Me! Write a sub that requests a positive integer between 10 and 20 (assume it is correctly entered) Display each odd number from one to entered integer in ONE messagebox (build the message in a string then display it) IE 8580, mason@clemson.edu

Answer for the Check IE 8580, mason@clemson.edu