cs 0004 –lecture 3

10
CS 0004 –Lecture 3 Jan 10, 2011 Roxana Gheorghiu

Upload: cheng

Post on 14-Feb-2016

44 views

Category:

Documents


0 download

DESCRIPTION

CS 0004 –Lecture 3. Jan 10, 2011 Roxana Gheorghiu. VBA Controls and Variables. Controls (components) = building block of a GUI Labels Textboxes Buttons Check boxes Radio buttons Variables = identifiers used in a program to hold some data Algebra: x =5; y = x * x ; VBA: - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CS 0004 –Lecture 3

CS 0004 –Lecture 3Jan 10, 2011

Roxana Gheorghiu

Page 2: CS 0004 –Lecture 3

Controls (components) = building block of a GUI ◦ Labels◦ Textboxes◦ Buttons◦ Check boxes◦ Radio buttons

Variables = identifiers used in a program to hold some data

◦ Algebra: x=5; y=x*x;◦ VBA:

Dim x as Integer Dim y as Integer x =5 y =2*x

VBA Controls and Variables

Page 3: CS 0004 –Lecture 3

Each type is design to store a particular type of data

Possible data types: Integer: -1000, 10, 0, 20000Double: -10.5, 0.0, -200.3456String : “ this is a string”, “anotherOne”Date…

2-phase process DeclarationAssignment of value (usage)

Variable Types

Page 4: CS 0004 –Lecture 3

Create the containerDeclarations

Phase that creates a variableDim varName as Type

Dim name as String or Dim x as Integer or …Rules for variable names:

Can only use letters, numbers and underscore (_)Must start with a letter or underscoreCannot have spacesCannot use special charactersCannot be a keyword

PriceAsInteger

Page 5: CS 0004 –Lecture 3

Fill the containerAssignment of value =gives the variable a value

By assigning a valuemyName =“Roxana”; shoesPrice =30

By assigning a value from another variablenewAddress =oldAddress

By using arithmetic operations PriceAsInteger10

0000

Page 6: CS 0004 –Lecture 3

Fill the containerAssignment of value =gives the variable a value

By assigning a valuemyName =“Roxana”; shoesPrice =30

By assigning a value from another variablenewAddress =oldAddress

By using arithmetic operations

Page 7: CS 0004 –Lecture 3

Addition: +◦ x = 5+5; x=y+5

Subtraction: -◦ x = 100 -2; myBudget =mySalary -2000

Division: /◦ z = X/2

Multiplication: *◦ x = 10*y◦ y = 2*5;

Exponentiation: ^◦ y = x^2◦ z = 2^3

Arithmetic operations

Page 8: CS 0004 –Lecture 3

Incrementing NumbersDim x as Integerx =x+1 OR x+ =1

Decrementing Numbers Dim y as Integer y=y-1 OR y-=1

Arithmetic Shorthand

Page 9: CS 0004 –Lecture 3

RoundingMath.Round(number, precision)

Math.Round(2.182 , 1) =2.2Math.Round(2.182) =2.0

Modulo =the reminder after you divide the two numbers5 Mod 3 =221 Mod 2 =1

Square RootMath.Sqrt(9)

More Arithmetic Operations

Page 10: CS 0004 –Lecture 3

Compute the perimeter

Write a program that :Allows a user to give two values: length and widthreads the values of length and the width computes the perimeter when Calc button is

pressed. displays this value on the screen.exits when Exit button is pressed