情報基礎 B Lecture 8 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.

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

259 Lecture 10 Spring 2013 Advanced Excel Topics – More User Defined Functions; Conditional Statements.
情報基礎 B Lecture 5 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
Computer Science & Engineering 2111 IF and Boolean Functions 1 CSE 2111 Lecture-IF and Boolean Functions.
情報基礎 A Lecture 10 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
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.
30/04/ Selection Nested If structures & Complex Multiple Conditions.
VB PROJECT “PROJECT SAMPLES”. For Next Loops Design a VB program that displays in a picture box the first N multiples of an input integer Input 3 exam.
School of Computing Science CMT1000 Ed Currie © Middlesex University 1 CMT1000: Introduction to Programming Ed Currie Lecture 5B: Branch Statements - Making.
Developing Software Applications Introduction to Programming Fundamentals Scoping in VB Simple Ifs in VB.
VBA Programming Session #2. Things to Review  Variables  Procedures: Subs & Functions  If…Then  For…Next.
Chapter 4 MATLAB Programming Logical Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
 Create a small exam that calculate the grade it self  Create a small program to do.
Akil M. Merchant CGS 2060 – Spring 2011 For Dr. David Gaitros CGS Spring Continuing to Excel with Excel.
情報基礎 A Lecture 15 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
Class 3 Programming in Visual Basic. Class Objectives Learn about input/output Learn about strings Learn about subroutines Learn about arrays Learn about.
Chapter 4: The Selection Process in Visual Basic.
ENGR 112 Decision Structures.
Types and Loops.
Week 2.  Macros revisited  The VBA Editor  The object model  Using variables  If statements.
# 1# 1 Searching andSorting What is selection sort? What is bubble sort? What is binary search? CS 105 Spring 2010.
Lesson 5: Working with Formulas and Functions Logical and 3D Formulas.
VBA (continued) DSC340 Mike Pangburn. Consider a quite different example  You need to compute someone’s exact age.  The math is actually somewhat complicated.
Week 4.  Recap – Ranges  For Each Loops  Ranges Referencing Range Objects  Set (keyword)
Visual Basic Programming Making Decisions: Loops & Decision Structures ©Copyright by Ronald P. Kessler, Ph.D.
Control Structures.  Need to have program statements that control execution flow  Simple statements to branch execution based on conditions (If/Then/Else)
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.
22/11/ Selection If selection construct.
Overview of VBA Programming & Syntax. Programming With Objects u Objects –Properties: attributes or characteristics of an object (e.g., font size, color,
1 Flow Control Ifs, loops. 2 Data Type At the lowest level, all data in a computer is written in 1’s and 0’s (binary) How the data gets interpreted, what.
Chapter 16: Programming Structures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
CS 101 Test 2 Study Guide Acronyms RAD - Rapid Application Development IDE - Integrated Development Environment GUI - Graphical User Interface VB - Visual.
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!!
ME 142 Engineering Computation I Using Subroutines Effectively.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
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.
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.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
ME 142 Engineering Computation I Using Subroutines Effectively.
Visual Basic Objects / Properties / Methods PropertyAdjective ObjectNoun Part of the application Attribute MethodVerb Action to do something.
31/01/ Selection If selection construct.
1 Microsoft® Visual Basic®.NET Language # 2. 2 Flow-Control Statements If … End If Select Case … End Select For… Next Do … Loop Exit.
Controlling Program Flow with Looping Structures
情報基礎 A Lecture 9 Takeshi Tokuyama ・ Jinhee Chun Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Microsoft Excel Prepared by the Academic Faculty Members of IT.
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
情報基礎 A Lecture 12 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
More Visual Basic Code: if-then-else, for loops Controls: Multiple forms, List Boxes, Radio buttons, frames,
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.
EXCEL INSTRUCTOR:CHITRANGI DOSHI
259 Lecture 10 Spring 2017 Advanced Excel Topics – More User Defined Functions; Conditional Statements.
IE 8580 Module 4: DIY Monte Carlo Simulation
Visual Basic 6 (VB6) Data Types, And Operators
VB.Net Programming Console Application
Chapter 4 MATLAB Programming
البرمجة بلغة فيجول بيسيك
مراحل كتابة البرنامج بلغة فيجول بيسك ستديو
البرمجة بلغة فيجول بيسك ستوديو
Data Types List Box Combo Box Checkbox Option Box Visual Basic 6.0
Excel: Formulas & Functions II Participation Project
Visual Basic Programming
情報基礎B   Lecture 7 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
情報基礎B   Lecture 6 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
REACH Computer Resource Center
GCSE Computing:: Selection (IF statements)
Presentation transcript:

情報基礎 B Lecture 8 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information Systems

PROGRAMMING VBA DATA TYPE, IF-THEN-ELSE

Data type (Numeric) Data type name DataValue rangeSize Byte 0 to 2551 byte Integer -32,768 to 32,7672 byte LongLong Integer -2,147,483,648 to 2,147,483,647 4 byte Single Precision floating point numbers ±3.4×10 38 to ±1.4× byte Double Double precision floating point numbers ±1.8× to ±4.9× byte

Data type (Others) Data typeValue BooleanTrue, False StringValues or numbers Date100/Jan/1 to 9999/Dec/31 Currency Larger than Long, 922,337,203, to 922,337,203,685, Variant Numeric and non-numeric values

Variables A box to store a value Variable declaration – e.g. prepare a box “x” to store integer value – Dim x As Integer Declare a Integer type variable “x” – Dim name As String Declare a String type variable “name” x x name

1Sub yeartrans2() 2‘Transform Heisei into A.D. 3 4 Dim x As Integer 5 Dim y As Integer 6 Dim name As String 7 8 name = InputBox(“Enter your name.”) 9 x= InputBox(“Transform Heisei into A.D.” & name & “, enter Heisei year.”) 10 y = x MsgBox name & “, Heisei” & x & “is A.D.” & y & ”.” 13 14End Sub Variables (Integer and String) and Data IO (InputBox and MsgBox)

“IF” in Excel Function Branch with “TRUE” or “FALSE” IF(logical_test, value_if_true, value_if_false) Logical formula or Cell number String with “” or just numbers

“IF” in Excel Function Grading program in previous lecture – Pass if score is more than 60, fail otherwise D16 = IF(A1>=60, “Pass”, “Fail”) Pass FALSE TRUE Fail >=60

I f - Then - Else in VBA Action1 FALSE TRUE Action2 logical_test If logical_test Then Else End If Action1 Action2

Grading Program Grade score if it is Pass or Fail – Pass if score is more than 60, fail otherwise Pass FALSE TRUE Fail >=60

Grading Program 1Sub seiseki1() 2‘Grading Program 3 4 Dim score1 As Integer 5 Dim name1 As String 6 7 name1 = InputBox(“Enter your name.”) 8 score1 = InputBox(“Enter your score.”) 9 10 If score1 => 60 Then 11 MsgBox “Congratulations!” & name1 & ”, You passed the exam.” 12 Else 13 MsgBox name1 & ”, You failed the exam.” 14 End If 15 16End Sub

Nesting “IF” in Excel Function A A TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE F F B B C C D D >=90 >=80 >=70 >=60

Nesting “IF” in Excel Function Grade – A100 > Score >= 90 – B 90 > Score >= 80 – C 80 > Score >= 70 – D 70 > Score >= 60 – F 60 > Score =IF(B2>=90, ”A”, IF(B2>=80, ”B”, IF(B2>=70, ”C”, IF(B2>=60, ”D”, “F”)))) =IF(B2>=90, ”A”, IF(B2>=80, ”B”, IF(B2>=70, ”C”, IF(B2>=60, ”D”, “F”))))

If logical_test1 Then ElseIf logical_test2 Then Else End If I f - Then - Else in VBA Action1 FALSE TRUE logical_test1 logical_test2 Action2 Action3 FALSE TRUE Action1 Action2 Action3

Grading Program If-Then-Else 1Sub seiseki2() 2‘Grading Program If-Then-Else 3 4 Dim score2 As Integer 5 Dim name2 As String 6 7 name2 = InputBox(“Enter your name.”) 8 score2 = InputBox(“Enter your score.”) 9 10 If xxxxx Then 11 MsgBox name2 & ”, Your grade is A.” 12 ElseIf xxxxx Then 13 MsgBox name2 & ”, Your grade is B.” 14 ElseIf xxxxxx Then 15 MsgBox name2 & ”, Your grade is C.” 16 ElseIf xxxxx Then 17 MsgBox name2 & ”, Your grade is D.” 18 Else 19 MsgBox name2 & ”, Your grade is F.” 20 End If 21 22End Sub

Nesting If-Then-Else A A TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE F F B B C C D D >=90 >=80 >=70 >=60

Grading Program nesting If-Then-Else 1Sub seiseki3() 2‘Grading Program If-Then-Else 3 4 Dim score3 As Integer 5 Dim name3 As String 6 7 name3 = InputBox(“Enter your name.”) 8 score3 = InputBox(“Enter your score.”) 9 10 If Then 11 If Then 12 If Then 13 If Then 14 MsgBox name3 & ”, Your grade is A.” 15 Else 16 MsgBox name3 & ”, Your grade is B.” 17 End If 18 Else 19 MsgBox name2 & ”, Your grade is C.” 20 End If 21 Else 22 MsgBox name2 & ”, Your grade is D.” 23 End If 24 Else 25 MsgBox name2 & ”, Your grade is F.” 26 End If 27 28End Sub