1 / 10

CS 0004 –Lecture 3

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:

cheng
Download Presentation

CS 0004 –Lecture 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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: • Dim x as Integer • Dim y as Integer • x =5 • y =2*x

  3. Variable Types • Each type is design to store a particular type of data • Possible data types: • Integer: -1000, 10, 0, 20000 • Double: -10.5, 0.0, -200.3456 • String : “this is a string”, “anotherOne” • Date • … • 2-phase process • Declaration • Assignment of value (usage)

  4. Create the container • Declarations • Phase that creates a variable • DimvarNameasType • Dim name as String or Dim x as Integer or … • Rules for variable names: • Can only useletters, numbers and underscore (_) • Must start with a letter or underscore • Cannot have spaces • Cannot use special characters • Cannot be a keyword Price As Integer

  5. Fill the container • Assignment of value =gives the variable a value • By assigning a value • myName =“Roxana”; shoesPrice =30 • By assigning a value from another variable • newAddress =oldAddress • By using arithmetic operations 100000 Price As Integer

  6. Fill the container • Assignment of value =gives the variable a value • By assigning a value • myName =“Roxana”; shoesPrice =30 • By assigning a value from another variable • newAddress =oldAddress • By using arithmetic operations

  7. Arithmetic operations • 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

  8. Arithmetic Shorthand • Incrementing Numbers Dim x as Integer x =x+1 OR x+ =1 • Decrementing Numbers Dim y as Integer y=y-1 OR y-=1

  9. More Arithmetic Operations • Rounding • Math.Round(number, precision) • Math.Round(2.182 , 1) =2.2 • Math.Round(2.182) =2.0 • Modulo =the reminder after you divide the two numbers • 5 Mod 3 =2 • 21 Mod 2 =1 • Square Root • Math.Sqrt(9)

  10. Compute the perimeter • Write a program that : • Allows a user to give two values: length and width • reads 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

More Related