Introduction to Programming and VBScript - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Introduction to Programming and VBScript

Description:

5. A computer can repeat a group of operations ... for grouping for addition ^ for exponentiation - for subtraction - for negation ... – PowerPoint PPT presentation

Number of Views:1444
Avg rating:3.0/5.0
Slides: 24
Provided by: patmc2
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Programming and VBScript


1
Introduction to Programming and VBScript
2
Data and Information
  • Data are raw facts
  • Examples of data include transactions, dates,
    amounts, etc.
  • Information are data that have been processed
    into a usable form
  • Information includes tables, documents, charts,
    etc.
  • Goal of computer applications is to process data
    into information

3
Six Basic Computer Operations
  • 1. A computer can receive (input) data
  • 2. A computer store data in memory
  • 3. A computer can perform arithmetic and
    manipulate text strings
  • 4. A computer can compare the contents of two
    memory locations and select one of two
    alternatives
  • 5. A computer can repeat a group of operations
  • 6. A computer can output information (processed
    data)

4
Computer Operations
5
Programs and Programming
  • A program is a very specific set of rules that
    tell the computer which switches should be "ON"
    or "OFF".
  • The process of creating a program is called
    programming.
  • The computer only knows what it is told through
    programs, so they must be accurate and very
    specific.

6
What is Programming?
  • Deciding if there is a task to be accomplished or
    problem to be solved using a computer, eg, is
    there a need for a program?
  • Determining the nature of the task or problem,
    eg, what must the program do?
  • Developing a plan that will accomplish the task
    or solve the problem, eg, generating the
    step-by-step process that the program will follow
    (algorithm)
  • Converting the plan into a computer language
    program
  • Testing the program to ensure it accomplishes
    task or solves problem defined earlier
  • Implementing the program to accomplish the task
    or solve the problem

7
Types of Computer Languages
  • Procedural Monolithic programs that run from
    start to finish with no intervention from user
    other than input
  • Basic, QBasic, QuickBasic
  • COBOL, FORTRAN, C
  • Object Oriented/Event Driven (OOED) Programs
    that use objects which respond to events use
    small segments ot code for each object
  • Visual Basic
  • Visual C
  • Scripting languages Simplified languages that
    must be interpreted by other software (eg,
    browser, server software) gtgtVBScript, Javascipt,
    PerlScript

8
Object-Oriented Programming (OOP)
  • OOP uses objects, or self contained modules that
    combine data and program code which pass strictly
    defined messages to one another.
  • OOED is easier to work with, because it is more
    intuitive than traditional programming methods.
  • Visual Basic is almost a OOP language
  • Users can combine the objects with relative ease
    to create new systems or extend existing ones.
  • Properties of objects are attributes associated
    with an object
  • Methods of objects are those activities that the
    object can carry out
  • Objects respond to events

9
Web Development with Scripting
  • Web development creating applications that run
    on either or both the server and browser software
  • Web development process
  • 1. Define problem (functional definition)
  • 2. Determine form of input from browser (html)
  • 3. Determine form of output to browser (html)
  • 4. Write and debug client-side script to
    pre-process browser input
  • 5. Write and debug server-side script to process
    input to generate output to browser in form of
    HTML
  • 6. Test entire project (client and server side)
  • Final project must solve problem defined in 1st
    step

10
Declaring Variables
  • Declare ALL variables with the DIM statement
  • General form
  • Dim Variable1, variable2
  • For example,
  • Dim MyName, MyValue
  • Dim Taxes, Price
  • Two or more variables can be declared with same
    Dim statement
  • Begin ALL pages with the ltOption Explicitgt
    statement even before the ltHTMLgt statement. This
    forces all variables to be declared--a good thing
    to do
  • If you fail to declare a variable after the
    Option Explicit statement has been entered, an
    error occurs at Run time

11
Keeping Tags and Code Apart
  • In an .asp page, tags and code are separated by
    delimiters
  • Tags appear and work in an asp document just like
    they do in a normal HTML page.
  • Code is interspersed in page surrounded by lt and
    gt code delimiters, eg,
  • lt Dim ftsize, ftcolor gt
  • Multiple lines of code can be surrounded by one
    set of code delimiters,eg,
  • lt Dim ftsize, ftcolor
  • For ftsize 1 to 7 gt

12
Using comments
  • You can add internal documentation in the form of
    VBScript comments by using apostrophes
  • Anything inside code delimiters beginning with an
    apostrophe is ignored by the server when
    interpreting an asp page, eg
  • lt
  • This code loops 7 times changing the
    ltignored
  • font size each time through the loop
    ltignored
  • for ftsize 1 to 7 ltexecuted
  • You can delete code without removing it by
    preceding it with an apostrophe

13
Line Continuation
  • VbScript code statements in code delimiters can
    be continued by ending a statement with a space
    and an underline, eg,
  • lt if weekday(date) gt 3 and _
  • weekday(date) lt 6 then
  • gt
  • is the same as
  • lt if weekday(date) gt 3 and weekday(date) lt 6
    then gt

14
Assignment Statements
  • Used to assign a value to a variable, eg
  • lt Taxes VideoPrice TaxRate gt
  • A variable or expression will be on right of
    assignment statement
  • An expression is a combination of one or more
    variables and/or constants with operators
  • Operators are symbols used for carrying out
    processing

15
Arithmetic Operators
  • () for grouping for addition
  • for exponentiation - for subtraction
  • - for negation
  • for multiplication
  • / for division
  • \ for integer division
  • mod for modulus

16
Hierarchy of Operations
  • Operations within parentheses ( )
  • Exponentiation ()
  • Negation (-)'
  • Multiplication and division (,/)
  • Integer division (\)
  • Modulo arithmetic (Mod)
  • Addition and subtraction (,-)
  • String concatenation ()

17
Arithmetic Example
  • ltGross 3 (Salary - Taxes)2 Bonus/Months
    gt
  • 3 1 2 5
    4 (order)
  • Order
  • 1 Subtract Taxes from Salary
  • 2 Square the result
  • 3 Multiply this result by 3
  • 4 Divide Bonus by Months
  • 5 Add result to first expression

18
Displaying Variable Values
  • To output the result of an assignment statement,
    use the following statement in the asp page
  • lt variablegt
  • For example, to compute taxes and total cost
  • lt Option Explicit gt
  • ltHTMLgt
  • lt Dim TotalCost, Videoprice, TaxRate, Taxes
  • VideoPrice 2.99
  • TaxRate 0.07
  • Taxes TaxRate VideoPrice
  • TotalCost VideoPrice Taxes gt
  • lt TotalCostgt
  • lt/HTMLgt
  • Enter this code in Notepad and save as
    Compute.asp and add this line to default.asp lta
    href compute.aspgtCompute Example lt/agt

19
More on Delimiters
  • If is possible (and often useful) to include code
    delimiters inside an HTML tag, eg,
  • ltfont size ltftsizegtgt
  • In this case, instead of displaying the value of
    the ftsize variable, the HTML ltfont size gt tag
    takes on the value of ftsize
  • If the ftsize variable is equal to, say, 5 then
    the above tag is the same as
  • ltfont size 5gt
  • But since ftsize is a variable, it can take on
    many different values changing the size of the
    font

20
Working with strings
  • It is possible to work with strings, that is,
    sequences of characters
  • Strings can be concatenated, that is, combined
    with the ampersand operator, eg,
  • lt Option Explicit gt
  • ltHTMLgt
  • lt Dim FirstName, LastName, Name
  • FirstName Bill
  • LastName Gates
  • Name FirstName LastName gt
  • lt Namegt
  • lt/HTMLgt
  • Whats wrong with the assignment statement?
  • Correct it and save the file as String.asp and
    add this line to default.asp lta href
    String.aspgtString Example lt/agt

21
Symbolic Constants
  • We can assign a name to a constant with the Const
    statement
  • lt const constant name value gt
  • Example
  • lt Const TaxRate 0.07gt
  • This assigns the constant the same value
    throughout the program

22
Using Functions
  • Sometimes we carry out a specific operation for
    which aVBScript function already exists to
    compute a single value
  • To do this, we use a function that is nothing
    more than an operation that takes a multiple
    arguments and generates a single value
  • variable functionName(arg1, arg2, )
  • Example functions
  • Date to return the current date
  • Int to return the integer part of a number
  • Len to return the length of a string

23
Other Functions
  • Other useful functions include
  • Abs for absolute value Sqr for square root
  • Ucase/Lcase to convert to upper/lower case
  • DateValue for the date corresponding to string
    argument
  • FormatCurrency to display a number as currency
  • Instr to return the location of a substring in a
    string
  • Example change the ltTotalcostgt statement in
    compute.asp to lt formatcurrency(Totalcost)gt
    and run it again. Note the difference in the
    output.
  • For more information on VBScript functions, go to
    http//msdn.microsoft.com/scripting/VBScript/doc/v
    bstoc.htm and select Functions
Write a Comment
User Comments (0)
About PowerShow.com