Arrays and others. Annoucement Today’s office hour move to Friday 1:00PM to 3:00PM Today’s office hour move to Friday 1:00PM to 3:00PM Today Today  Call.

Slides:



Advertisements
Similar presentations
1 VBA Introduction. Basic Components 2 VBA LANGUAGE OFFICE OBJECTS EXCEL OBJECTS ACCESS OBJECTS WORD OBJECTS OUTLOOK OBJECTS POWERPOINT OBJECTS.
Advertisements

Excel and Visual Basic. Outline Data exchange between Excel and Visual Basic. Programming VB in Excel.
Modeling using VBA. Covered materials -Userforms -Controls -Module -Procedures & Functions -Variables -Scope.
Introduction to C Programming
Arrays. What is an Array? An array is a way to structure multiple pieces of data of the same type and have them readily available for multiple operations.
Converting Numbers Between Bases. While the quotient is not zero…  Divide the decimal number by the new base.  Make the remainder the next digit to.
Passing Arguments Question Example: IS1102 Exam Autumn 2001.
VBA Modules, Functions, Variables, and Constants
Chapter 4 - Visual Basic Schneider
Introduction to Computing Dr. Nadeem A Khan. Lecture
Chapter 41 Sub Procedures, Part II (Continue). Chapter 42 Local Variable A variable declared inside a Sub procedure with a Dim statement Space reserved.
1 Chapter 7 Arrays. 2 Outline and Objective In this chapter we will Learn about arrays One-dimensional arrays Two-dimensional arrays Learn about searching.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
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.
VBA & Excel Barry L. Nelson IEMS 465 Fall Quarter 2003.
Apply Sub Procedures/Methods and User Defined Functions
ISAT 252 Introduction to Arrays. Should have read 2 Chapter 8 –pp , and pp
IE 212: Computational Methods for Industrial Engineering
Array Processing: Exercises School of Business Eastern Illinois University © Abdou Illia, Spring 2002 (Week 10, Friday 3/28/2003)
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.
Arrays and 2D Arrays.  A Variable Array stores a set of variables that each have the same name and are all of the same type.  Member/Element – variable.
Sub procedures School of Business Eastern Illinois University © Abdou Illia, Spring 2002 (Week 6, Friday 2/21/03)
VB Core II Conditional statements Exception handling Loops Arrays Debugging.
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Arrays Chapter 8. Chapter 8 - Part 12 Variable and Variable Array Variable Stores only one value Variable Array Variable that has 1 symbolic name but.
Arrays. Overview u General Discussion  Uses  Structure  Declaration u Searching u Control Arrays.
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
‘Tirgul’ # 2 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #2.
6-1 Chapter 6 Working with Arrays in VB.NET. 6-2 Learning Objectives Understand the use of list and table arrays in VB.NET projects and the difference.
Chapter 3 w Variables, constants, and calculations DIM statements - declaration temporary memory locations identifier, data type, scope data types - values.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Scripting Languages Diana Trandab ă ț Master in Computational Linguistics - 1 st year
Using Recursion to Convert Number to Other Number Bases Data Structures in Java with JUnit ©Rick Mercer.
String and General Procedures. Answer to the last question of Exam 1 Start Get a number Divide the Number By 2 Is the quotient Equal to 1? Print The Remain.
Visual Basic Programming I 56:150 Information System Design.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
1 CSC103: Introduction to Computer and Programming Lecture No 24.
Debugging, Static Variables, ByRef, ByValue Chapt. 6 in Deitel, Deitel and Nieto.
Variables Hold information that may be manipulated, used to manipulate other information or remembered for later use A storage location in memory (RAM)
CECS 5020 Computers in Education Visual Basic Variables and Constants.
110 E-1 Variables, Constants and Calculations(2) Chapter 3: Operations on variables, scope of a variable, formatting data Doing Arithmetic.
Sub Procedures; Passing Values Back From Sub Procedures Passing by reference Passing by value.
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.
Loop and repetition. Today Passing values to and back from Sub procedures Option Buttons Do While Loops For Loops Population Growth.
Data and variables in Visual Basic. Annoucement Lecture on Thursday 7:30PM C106 Visual Basic download: 
Overview of Previous Lesson(s) Over View VP is the methodology in which development allows the user to grab and use the desired tools like menus, buttons,
What is Binary Code? Computers use a special code of their own to express the digital information they process. It's called the binary code because it.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Third Edition by Tony Gaddis.
Subroutines and Functions Chapter 6. Introduction So far, all of the code you have written has been inside a single procedure. –Fine for small programs,
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 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
CS0004: Introduction to Programming
Programming Right from the Start with Visual Basic .NET 1/e
A variable is a name for a value stored in memory.
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
Visual Basic 6 (VB6) Data Types, And Operators
Binary Number System Lesson objectives:
Single Dimensional Arrays
2. Understanding VB Variables
CS285 Introduction - Visual Basic
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Chapter 8 - Functions and Functionality
Dividing a decimal by a whole number
Converting Numbers Between Bases
SPL – PS2 C++ Memory Handling.
Presentation transcript:

Arrays and others

Annoucement Today’s office hour move to Friday 1:00PM to 3:00PM Today’s office hour move to Friday 1:00PM to 3:00PM Today Today  Call by reference and call by value  Variable scopes  Arrays  Debugging

Call by reference Passing the whole variable memory block to the sub procedure Passing the whole variable memory block to the sub procedure If inside is changed, outside will be changed too. If inside is changed, outside will be changed too. How: How:  Private Sub Add(num1 as integer, num2 as integer)  Call Add(x,y)

Call by value Only copy the value of the variable to the sub procedure. Only copy the value of the variable to the sub procedure. Inside changes will not affect the outside variables. Inside changes will not affect the outside variables. How: How:  Private Sub Add(num1 as integer, num2 as integer)  Call Add((x),y) Call by reference and call by value also apply to the function procedure. Call by reference and call by value also apply to the function procedure. When to use. When to use.

Scope of a variable Local scope. Local scope.  Variable declared in a sub procedure  It only exists in this sub procedure. Form-level scope. Form-level scope.  Variable declared out of any sub procedure.  Any sub procedure can read it.

Arrays Array is a special type of variable Array is a special type of variable Regular Variables hold one value Regular Variables hold one value Arrays hold may values - subscripts Arrays hold may values - subscripts X(1), X(2), X(3), X(4), X(5) X(1), X(2), X(3), X(4), X(5) Arrays are like subscripts – refer to different values stored in the same variable Arrays are like subscripts – refer to different values stored in the same variable Pp Pp

What Arrays Do Suppose Data is an array. Suppose Data is an array. Data(1)Data(2)Data(3)Data(4)Data(5) First value Second value Third value Fourth value Fifth value

Declaring Arrays Use Dim key word to declare arrays, just as what we do for variables. Use Dim key word to declare arrays, just as what we do for variables.  Dim Data(1 to 50) As Single  Dim Species(1 to 4) As String Accessing values in an array with subscript. Accessing values in an array with subscript.  Data(44) = 22.5;  Species(1) = “ACTGACTCGTAACGT” Red Number is INDEX Red Number is INDEX

Matrices: 2-dimensional Arrays Declaration Declaration  Dim Data(1 to 50, 1 to 20) As Single Accessing Accessing  Data(2,4)=100 The range of the subscript can be between any integers. The range of the subscript can be between any integers.  Dim WeekendMorning(6 to 7, 7 to 12) As String

Passing array to a sub procedure Array can be passed as an argument to sub procedures of function procedures. Array can be passed as an argument to sub procedures of function procedures.  Private Sub ProcName(ArrayName() as Integer)  Call ProcName(Array1) Array can only be called by reference. Array can only be called by reference. Function Ubound(ArrayName,2) Function Ubound(ArrayName,2)

ReDim Use ReDim when declaring an array size based on a variable Use ReDim when declaring an array size based on a variable Also called dynamic array Also called dynamic array User tells you there are 50 values (count = 50) User tells you there are 50 values (count = 50) ReDim Values(1 to count) as Single ReDim Values(1 to count) as Single

Decimal to Binary calculator

Flow chart Start Get a number Divide the Number By 2 Is the quotient Equal to 1? Print The Remainder to the left of previous remains No Print 1 To the left of Previous remainders End Yes Output number If number Equal to 1 or 0 Yes No

Convert the first decision to code IF number <> 0 OR number <> 1 THEN Do the conversion part END IF Call OutputNumber(number)

Code fragment for the loop Do While quotient <> 1 quotient = number \ 2 reminder = number mod 2 number = quotient call PrintReminder() Loop

Problems So far we have already solved the Decision structure and loop structure. So far we have already solved the Decision structure and loop structure. Problems not solved. Problems not solved.  All previous reminders need to be stored.  How many? Print 1 To the left of Previous remainders

Steps First we need determine how many places in the converted binary number First we need determine how many places in the converted binary number  Int(Log(Dec) / Log(2)) + 1 Second, declare a dynamic array to store all the output numbers. Second, declare a dynamic array to store all the output numbers.  ReDim Bin(1 to binplaces) as String In the do while loop, put reminders of each step in the Bin array. Beware of the order In the do while loop, put reminders of each step in the Bin array. Beware of the order

Output function Private Sub Output(rems() As String) ‘Print the binary array in the picOutput picture box End Sub Output number

Debugging tools in VB Break points Break points

Debugging tools in VB(2) Immediate Window Immediate Window

Debugging tools in VB(3) Watch window and local window Watch window and local window

Friday  Do the program that convert 10 base value to binary.