Quiz 2. Quiz 2 What is output (5 Marks) [8 min] X = 987 Y = X Z = 0 Do Do While (Y > 0) Z = Z + Y Mod 10 Y = Y \ 10 Loop Y = Z Z = 0 Loop Until (Y < 10)

Slides:



Advertisements
Similar presentations
CSI 1306 PROGRAMMING IN VISUAL BASIC PART 2. Part 2  1. Strings  2. Translating Conditional Branch Instructions  3. Translation Set 2  4. Debugging.
Advertisements

PROGRAMMING IN VISUAL BASIC PART 1
Object Oriented Programming A programming concept which views programs as objects with properties and ways to manipulate the object and the properties.
Quiz 1. What is the Output of this code fragment when N = 85 (3 Marks) [5 Minutes] A = N \ 10 B = N Mod 10 C = 0 If (N Mod 2 = 0) Then C = C + 1 Else.
CSI 1306 PROGRAMMING IN VISUAL BASIC PART 5. Part 5  1. Procedures  2. Sub Procedures  3. Function Procedures.
CSI 1306 BIASU Start to Finish. Background  This is a very simple project. It is not the difficulty that is being presented but the different ways one.
Writing General Procedures Often you will encounter programming situations in which multiple procedures perform the same operation This condition can occur.
Visual Basic  Rick, Albert. 1. Visual Basic 1.0 (May 1991) was released for Windows at the Comdex/Windows World trade show in Atlanta, Georgia
Muffin Shop - if, calculations etc. (muffins, muffins2) Please use speaker notes for additional information!
Exploring Microsoft Excel 2002 Chapter 8 Chapter 8 Automating Repetitive Tasks: Macros and Visual Basic for Applications By Robert T. Grauer Maryann Barber.
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
Operations 343 Spreadsheet Modeling Week 15 Quiz Review Homework Review Course Review Lab session.
Break Processing Please use speaker notes for additional information!
Microsoft Access Using Visual Basic Routines. Visual Basic Datatypes Boolean Byte Currency Date Double Integer Long Object Single String Variant Hyperlink.
情報基礎 B Lecture 8 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
1 CC111 Lec9 : Visual Basic Visual Basic (3) Lecture 9.
Access VBA Programming for Beginners - Class 2 - by Patrick Lasu
VBA Lab 2 I ns.Samia Al-blwi. Visual Basic Grammar Object: Visual Basic is an object-oriented language. This means that all the items in Excel are thought.
VB Core II Conditional statements Exception handling Loops Arrays Debugging.
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.
110-G1 Motivation: Within a program, may have to perform the same computation over and over Many programs share the same computation (e.g. sorting) To.
# 1# 1 Searching andSorting What is selection sort? What is bubble sort? What is binary search? CS 105 Spring 2010.
Do Loop with Interest Please see speaker notes for additional information!
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 1B) UTPA – Fall 2011.
MS Visual Basic Applications Walter Milner. Event-driven programming Standard approach for GUIs Contrast with old character interfaces – program determines.
Introduction to MIS1 Copyright © by Jerry Post Introduction to MIS Appendix 12 Visual Basic.
Visual Basic Programming Making Decisions: Loops & Decision Structures ©Copyright by Ronald P. Kessler, Ph.D.
Introduction to VB.NET 2005 Dr. McDaniel IDS4704 Spring 2005.
‘Tirgul’ # 3 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #3.
CS285 Visual Basic 2 Department of Computing UniS 1 Statements in Visual Basic A statement is the fundamental syntactical element of a program smallest.
Lab 4 Range Review, Control Logic and Loops ► Range Review ► Control Logic and Loops ► Exercise.
Overview of VBA Programming & Syntax. Programming With Objects u Objects –Properties: attributes or characteristics of an object (e.g., font size, color,
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
1 CS105 Discussion 5 – Variables and If Announcements MP 1 due on Monday Midterm 1 on Tuesday If you need a conflict, request it NOW!!
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
Introduction to Video Game Programming (VGP) Mr. Shultz.
Visual Basic Programming I 56:150 Information System Design.
Macro’s Within excel. Most functionality can be driven from VBA VBA is the programming language that runs inside of excel. It uses visual basic as the.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 7 Where Can I Store This?
Debugging, Static Variables, ByRef, ByValue Chapt. 6 in Deitel, Deitel and Nieto.
Component 4/Unit 5-3. Data Type Alphanumeric (Character set: A-Z, 0-9 and some special characters) –Customer address, name, phone number, Customer ID,
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.
VBA Navigation, Conditionals, and Boxes. VBA Navigation.
1 Microsoft® Visual Basic®.NET Language # 2. 2 Flow-Control Statements If … End If Select Case … End Select For… Next Do … Loop Exit.
Lab 6 (1) Range Review, Control Logic and Loops ► Control Logic and Loops ► Exercise.
Loop Blocks Chapter 6 Part A. Program Blocks 1.Actions- commands, messages, methods 2.Branches- decisions to be made 3.Loops- actions to be repeated.
MIC305 Week 6 Beyond controls Review of properties Differences with VB6: using classes and instances Programming constructs.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
Visual Basic - Break Processing
Lecture 7 Methods (functions and subroutines) Parameter Passing
Visual Basic I Programming
IE 8580 Module 4: DIY Monte Carlo Simulation
Spreadsheet-Based Decision Support Systems
Method.
Final Exam Review Part 4 - VBA
Agenda Project 2 Supplement
البرمجة بلغة فيجول بيسيك
مراحل كتابة البرنامج بلغة فيجول بيسك ستديو
حلقات التكرار.
Exploring Microsoft Excel
Chapter 7: Using Functions, Subs, and Modules
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
The structure of programming
Visual Basic Programming
GCSE Computing:: Selection (IF statements)
Calculate 81 ÷ 3 = 27 3 x 3 x 3 3 x 3 x 3 x 3 ÷ 3 = This could be written as
Repetition - Counting and Accumulating
Sub 範例 Sub F ( X ) MsgBox(X ^ 2 ) End Function
Introduction to Computer Programming IT-104
Presentation transcript:

Quiz 2

Quiz 2 What is output (5 Marks) [8 min] X = 987 Y = X Z = 0 Do Do While (Y > 0) Z = Z + Y Mod 10 Y = Y \ 10 Loop Y = Z Z = 0 Loop Until (Y < 10) Z = X * 10 + Y MsgBox ("X = " & X & Chr(13) & _ "Y = " & Y & Chr(13) & _ "Z = " & Z)

Example 2 Travel Expenses

You need to calculate travel expenses for a company. The company assigns travel codes for each trip –TO – Trip to Toronto –MO – Trip to Montreal –KI – Trip to Kingston –RS – Research Trip –MK – Marketing Trip

Travel Expenses Since travel to the cities of Toronto Montreal and Kingston are frequent, a flat rate of the following: –Toronto - $70 + $50 per night –Montreal - $50 + $40 per night –Kingston - $40 + $40 per night

Travel Expenses Research Trips have the following calculation –$0.05 per km traveled –$60 per night stayed –$10 per meal

Travel Expenses Marketing Trips have the following calculation –$0.05 per km traveled –$80 per night stayed –$25 per meal

Algorithm Name Travel Given Code, KM, Nights, Meals Results – Refund Intermediates – None Definition Refund := Travel (Code, KM, Nights, Meals)

Algorithm Get Code Get KM, Nights, Meals If (Code = TO) Refund = * Nights Else if (Code = MO) Refund = * Nights Else if (Code = KI) Refund = * Nights Else if (Code = RS) Refund = 0.5 * KM + 60 * Nights + 10 * Meals Else if (Code = MK) Refund = 0.5 * KM + 80 * Nights + 25 * Meals Else Refund = -999 Give Refund

Write as a simple Sub( ) Get Code Get KM, Nights, Meals If (Code = TO).... Else Refund = -999 Give Refund Sub Trav1() Dim Code as String*2 Dim KM as Integer Dim Nights as Integer Dim Meals as Integer Dim Refund as Currency Code = InputBox("Code") KM = InputBox("KM") Nights = InputBox("Nights") Meals = InputBox("Meals") If (Code = "TO") Then Refund = * Nights ElseIf (Code = "MO") Then Refund = * Nights ElseIf (Code = "KI") Then Refund = * Nights ElseIf (Code = "RS") Then Refund = 0.5 * KM + 60 * Nights + 10 * Meals ElseIf (Code = "MK") Then Refund = 0.5 * KM + 80 * Nights + 25 * Meals Else Refund = End If MsgBox("R = " & Refund) End Sub

Write as Sub( param ) Get Code Get KM, Nights, Meals If (Code = TO)..... Else Refund = -999 Give Refund Sub Trav2( ByVal Code as String, _ ByVal KM as Integer, _ ByVal Nights as Integer, _ ByVal Meals as Integer, _ ByRef Refund as Currency) If (Code = "TO") Then Refund = * Nights ElseIf (Code = "MO") Then Refund = * Nights ElseIf (Code = "KI") Then Refund = * Nights ElseIf (Code = "RS") Then Refund = 0.5 * KM + 60 * Nights + 10 * Meals ElseIf (Code = "MK") Then Refund = 0.5 * KM + 80 * Nights + 25 * Meals Else Refund = End If End Sub

Write as Function( param ) Version 1 Dim Result Get Code Get KM, Nights, Meals If (Code = TO).... Else Refund = -999 Give Refund Function Trav3( ByVal Code as String, _ ByVal KM as Integer, _ ByVal Nights as Integer, _ ByVal Meals as Integer) as Currency Dim Refund as Currency If (Code = "TO") Then Refund = * Nights ElseIf (Code = "MO") Then Refund = * Nights ElseIf (Code = "KI") Then Refund = * Nights ElseIf (Code = "RS") Then Refund = 0.5 * KM + 60 * Nights + 10 * Meals ElseIf (Code = "MK") Then Refund = 0.5 * KM + 80 * Nights + 25 * Meals Else Refund = End If Trav3 = Refund End Function

Write as Function( param ) Version 2 without Dim Get Code Get KM, Nights, Meals If (Code = TO)... Else Refund = -999 Give Refund Function Trav4( ByVal Code as String, _ ByVal KM as Integer, _ ByVal Nights as Integer, _ ByVal Meals as Integer) as Currency If (Code = "TO") Then Trav4 = * Nights ElseIf (Code = "MO") Then Trav4 = * Nights ElseIf (Code = "KI") Then Trav4 = * Nights ElseIf (Code = "RS") Then Trav4 = 0.5 * KM + 60 * Nights + 10 * Meals ElseIf (Code = “MK") Then Trav4 = 0.5 * KM + 80 * Nights + 25 * Meals Else Trav4 = End If End Function

Utilizing the Sub (Param) Sub Main1() Dim C as String*2 Dim K as Integer Dim N as Integer Dim M as Integer Dim R as Currency C = InputBox("C") K = InputBox("K") N = InputBox("N") M = InputBox ("M") Call Trav2(C, K, N, M, R) MsgBox("Refund = "& R) End Sub

Utilizing using Function Sub Main2() Dim C as String*2 Dim K as Integer Dim N as Integer Dim M as Integer Dim R as Currency C = InputBox("C") K = InputBox("K") N = InputBox("N") M = InputBox ("M") ‘Use Either one of the following R = Trav3(C, K, N, M) ‘ R = Trav4(C, K, N, M) MsgBox("Refund = "& R) End Sub

Excel Worksheet ABCDEF 1EmpCodekmNightsMealsRefund 2123TO3?? 3234RE12848??

Using Excel Only What would the Function to be written in F2 to be copied down? = if (B2 = “TO”, * D2, if(B2 = “MO”, * D2, if(B2 = “KI”, * D2, if (B2 = “RS”, 0.05 * C * D * E2, if(B2 = “MK”, 0.05 * C * D * E2, -9999))))) What if Research department changes its rules (say $20 per meal) or corporate changes base rate for Toronto?

Using Excel with Visual Basic What what the function to be written in F2 to be copied down? = Trav3(B2, C2, D2, E2) Maintenance is easier under Visual Basic Note if Constants were used, maintenance becomes very ease