Programming continued - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Programming continued

Description:

When your writing code where will you spend the most time? ... Dim bday as Date 'I'm declaring x as an integer.' Dim var1, var2, var3 as Integer ... – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 23
Provided by: mil94
Category:

less

Transcript and Presenter's Notes

Title: Programming continued


1
Programming (continued)
  • Chapters 3.2 and 3.3

2
Review
  • Whats the difference between VB and other
    programming languages?
  • What is Pseudocode?
  • When your writing code where will you spend the
    most time?
  • At what point do you start writing code in VB?

3
Review
  • What is a reserved word?
  • What are properties? (examples)
  • If you get errors what should you do?

4
What we did last time?
  • Create a Form with 4 buttons labeled, Red, Blue,
    White, and Yellow. Each one will change the
    color of the background or foreground of a textbox

5
Math is Fun
  • Standard math operations
  • Addition
  • 55
  • Subtraction -
  • Division /
  • Multiplication
  • Exponentiation
  • 52 52

6
What more fun that Math
  • Incrementing Numbers
  • counter counter 1
  • counter 1
  • Decrementing Numbers
  • counter counter -1
  • counter - 1

7
More Math
  • Square Root
  • Math.Sqrt(9) 3
  • Rounding
  • Math.Round(number, precision)
  • Math.Round(2.1234) 2.0
  • Math.Round(2.182,1) 2.2
  • Modulo
  • 5 Mod 3 ??
  • 21 Mod 2 ??

8
More Math
  • Square Root
  • Math.Sqrt(9) 3
  • Rounding
  • Math.Round(number, precision)
  • Math.Round(2.1234) 2.0
  • Math.Round(2.182,1) 2.2
  • Modulo
  • 5 Mod 3 2
  • 21 Mod 2 1

9
Examples
  • a(bc)
  • abc
  • (bca)/a2
  • b(b-2)ac
  • Let a 2 b4 c2

10
Variables
  • Variables are buckets that hold data
  • Algebrax 5y 2xx and y are variables that
    can change
  • Visual Basicdim x As Integerdim y As Integerx
    5y 2 xtextBox.Text y
  • Valid Names (all rules in book)

11
Variable Types
  • So we have buckets of data types allow us to tell
    what the data is like
  • Variable x is an Integer
  • What types
  • Integer
  • Double
  • String
  • Date
  • VariantType

12
Defining Variables
  • In VB you need to define your variables
  • Dim varname as lttypegt
  • Dim x as Integer
  • Dim name as String
  • Dim bday as Date
  • Im declaring x as an integer.
  • Dim var1, var2, var3 as Integer

13
Strings
  • What is a string?
  • Your name. Your Street.
  • Strings are represented with quotes
  • This is a string
  • Dim s as Strings Foo Blats Grrrreat!

14
String Operations
  • Concatenation
  • Dim resp, auth as Stringresp Respect my
    auth authority!txtOutput.Text resp
    auth
  • Once ran the output will sayRespect my
    authority!

15
Math with Strings?
  • Need to convert String to Integers or Doubles
  • CDbl(ltstringgt)
  • CInt(ltstringgt)
  • Dim sum, count as Integer
  • Dim avg as Double
  • sum CInt(sum.Text)
  • count CInt(count.Text)
  • avg sum / count

16
More String Stuff
  • str.Length
  • The number of characters
  • str.ToUpper
  • foo Blat.ToUpper FOO BLAT
  • str.ToLower
  • Str.Trim
  • the text is here the text is here

17
Strings, Strings, Strings
  • str.Substring(m,n)
  • Visual.Substring(0,2) Vi
  • Visual.Substring(3,2) ua
  • 412.327.1234.Substring(5,3) 327
  • str.IndexOf(str2)
  • fanatic.IndexOf(a) 1
  • fanatic.IndexOf(ati) 3
  • fanatic.IndexOf(z) -1

18
Just a bit more on Strings
  • The Empty String
  • empty_str
  • empty_str.clear()
  • Initial Value
  • Dim today as String Monday
  • Multiple Line (continuation)
  • msgInvention is the _mother of necessity.

19
Code Comments
  • These are notes put in your code
  • Dim x, y as Integer
  • Dim avg as Double
  • the average is sum over total - bryan
  • avg x / y
  • Note These are very important if you want to get
    full credit on your projects.

20
The good and the bad
  • The With StatementWith lstElem.Items
    .Clear() .Add(foo) .Add(blat)
    .Add(bar)End With

21
Lets play
  • Create an application that has two inputs and a
    button to compute the sum of the two numbers.

22
Another Example
  • Write a program to request the team name, accept
    the number of wins and number of loses then
    display the followingltteam namegt won . of
    the time
Write a Comment
User Comments (0)
About PowerShow.com