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.

Slides:



Advertisements
Similar presentations
Introduction to Visual Basic for Applications programming in Excel.
Advertisements

Working with Intrinsic Controls and ActiveX Controls
Object Oriented Programming A programming concept which views programs as objects with properties and ways to manipulate the object and the properties.
Modeling using VBA. Covered materials -Userforms -Controls -Module -Procedures & Functions -Variables -Scope.
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.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Tutorial 12: Enhancing Excel with Visual Basic for Applications
Writing General Procedures Often you will encounter programming situations in which multiple procedures perform the same operation This condition can occur.
VBA Modules, Functions, Variables, and Constants
String Variables Visual Basic for Applications 4.
Using the Visual Basic Editor Visual Basic for Applications 1.
Visual Basic: An Object Oriented Approach 4: Simple Programming in VB.
ITP 150 Week 4 Variables. ITP Lecturer: A. Borquez2 Review:  Controls  Propeties  Events  Methods  Procedures  Functions BackStyleFillColor.
To type the VB code behind the command button (named cmdPush), Double-Click on the Push Me (caption) command button As a result the Visual Basic Code Window.
Arrays Array of Controls: several controls, of the same type (Class: a prototype for an object indicating the properties and methods), that have the same.
1 ISMT E-120 Desktop Applications for Managers Standardizing and Automating Work.
VBA & Excel Barry L. Nelson IEMS 465 Fall Quarter 2003.
 Excel – Basic Elements  Using Macros  Excel VBA Basics  Excel VBA Advanced.
Using the Select Case Statement and the MsgBox Function (Unit 8)
McGraw-Hill/Irwin Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. Extended Learning Module M Programming in Excel with VBA.
University of Toronto at Scarborough © Andria Hunter, Kersti Wain-Bantin CSCA01 VBA-3 1 Lecture Outline Variable Scope Calling another subprogram Programming.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #4: Working with Variables and User Interfaces IE 212: Computational Methods for Industrial Engineering.
1 VBA – podstawowe reguły języka Opracowanie Janusz Górczyński wg Microsoft Help.
1 Visual Basic for Applications (VBA) for Excel Prof. Yitzchak Rosenthal.
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
Why to Create a Procedure
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Microsoft Office Excel Copyright © 2008 Pearson Prentice Hall. All rights reserved
C Tokens Identifiers Keywords Constants Operators Special symbols.
Lab 01 Forms in excel Tahani ALdweesh Insert form into your project. 2. Change form’s properties. 3. Put controls on the form. 4. Change controls’
Outline Software and Programming Program Structure Tools for Designing Software Programming Languages Introduction to Visual Basic (VBA)
Access VBA Programming for Beginners - Class 2 - by Patrick Lasu
Types and Loops.
Date Variables Visual Basic for Applications 5. Objectives n In this tutorial, you will learn how to: n Reserve a Date variable n Use an assignment statement.
Applications Development
Overview of VBA Programming & Syntax. Programming With Objects u Objects –Properties: attributes or characteristics of an object (e.g., font size, color,
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
ME 142 Engineering Computation I Using Subroutines Effectively.
Chapter 3 w Variables, constants, and calculations DIM statements - declaration temporary memory locations identifier, data type, scope data types - values.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Visual Basic Programming I 56:150 Information System Design.
CompMathBSc, English 5 October 2006 Programming basics — continued  Arrays  Cycle Statements: Loops  Control Structures vs Conditions  Subs: Procedures.
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.
Chapter 6 Looping Structures. Do…LoopDo…Loop Statement Can operate statements repetitively Do intx=intx + 1 Loop While intx < 10 –The Loop While operates.
Visual Basic Objects / Properties / Methods PropertyAdjective ObjectNoun Part of the application Attribute MethodVerb Action to do something.
Chapter 4 Getting Started with VBA. Subroutines Subroutine is the logical section of code that performs a particular task. Subroutine is also called a.
Values, Types, and Variables. Values Data Information Numbers Text Pretty much anything.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
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.
Knowledge Base. Defining a Variable Dim statement Dim intXX As Integer Public in a Module Public dblNN As Double.
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
Addison Wesley is an imprint of © 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 3 Variables and Calculations.
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Introduction C# program is collection of classes Classes are collection of methods and some statements That statements contains tokens C# includes five.
The Advantage Series ©2005 The McGraw-Hill Companies, Inc. All rights reserved Chapter 12 Introducing Visual Basic for Applications Microsoft Office Excel.
Programming Right from the Start with Visual Basic .NET 1/e
A variable is a name for a value stored in memory.
VB Script V B S.
VBA - Excel VBA is Visual Basic for Applications
VBA - Excel VBA is Visual Basic for Applications
Working with Forms in Visual Basic
2. Understanding VB Variables
Microsoft Office Illustrated
Learning Excel Session 9 and 10 Dr. Chaitali Basu Mukherji.
CS285 Introduction - Visual Basic
EXCEL Creating An Array In VBA
Presentation transcript:

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 is a text box

Using User Form Work with Common Button, Text Box

Working with Combo Box

Working with List Box

Working with Image Control, Spin Button

Work with Multipage, Option controls

Work with Scroll Bar, Check Box, Frame controls

Work with additional controls

Modules & Procedures Module – collection of logically related procedures & functions grouped together Procedure – a group of ordered statements enclosed by Sub and End Sub Function – the same as a procedure, but also returns some value and is enclosed between Function and End Function key words

Procedure & Function Examples Sub ShowTime() Range("C1") = Now() End Sub Function sumNo(x, y) sumNo = x + y End Function Function: returns something Procedure: doesn’ t returns anything

Calling procedures vs. calling functions Sub z(a) MsgBox a End Sub Sub x() Call z("ABC") End Sub Sub y() z "ABC “ End Sub Sub ShowSum() varSum= Module1.sumNo(3,5) MsgBox varSum End Sub Function sumNo(x, y) sumNo = x + y End Function If there are several sumNo functions in several modules/forms, need to use the full name of the function

Passing Arguments by Value or by Reference Passing arguments by reference – – Is the VBA default – Means, if any changes happened to the argument variables, they will be preserved after the function/procedure finishes Passing arguments by value – – Is possible in VBA (by explicit definition) – Means, the pre-calling state of the argument variables will be preserved after the procedure/function finishes

Arguments by Ref/by Val. Examples Sub TestPassing1() Dim y As Integer y = 50 AddNo1 y MsgBox y AddNo2 y MsgBox y End Sub Sub AddNo1(ByRef x As Integer) x = x + 10 End Sub Sub AddNo2(x As Integer) x = x + 10 End Sub public Sub TestPassing2() Dim y As Integer y = 50 AddNo3 y MsgBox y End Sub private Sub AddNo3(ByVal x _ As Integer) x = x + 10 End Sub

Functions/Procedure Scope Use public to allow any module to call the function/procedure Use private to make limited access to the function/procedure (only from the owning module)

VBA Variables A variable is used to store temporary information within a Procedure, Function, Module … A variable name – Must start with letter and can ’ t contain spaces and special characters (such as “ & ”, “ % ”, “ \ ” ) – Can ’ t be any excel keyword ( “ if ”, “ while ”… ) – Can ’ t have identical name to any existing class ( “ Worksheet ”, “ Workbook ”… )

VBA Data Type Byte – positive integer numbers (0:255) Integer – integers (-32,768 : 32,767) Long – 4-byte integer Currency – for fixed-point calculations Single – 2-byte floating-point numbers Double – double-precision floating-point numbers Date – used to store dates and times as real numbers. String – contains a sequence of characters

Using Variables Declaring Variables – Format: Dim varibleName AS dataType – Examples: Dim myText As String Dim myNum As Integer Dim myObj As Range – The default value of any numeric variable is zero any string variable – “” (empty string) an Object variable – is nothing