Scripting Languages - PowerPoint PPT Presentation

About This Presentation
Title:

Scripting Languages

Description:

Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer and Netscape – PowerPoint PPT presentation

Number of Views:62
Avg rating:3.0/5.0
Slides: 29
Provided by: ariz151
Category:

less

Transcript and Presenter's Notes

Title: Scripting Languages


1
Scripting Languages
  • VBScript - Recognized mainly by Internet Explorer
    only - Netscape does have a plug-in
  • JavaScript - Recognized by Internet Explorer and
    Netscape
  • Perl - Used at the server side
  • Server v.s. Client programming
  • VBScript is similar to VB programming, but uses a
    subset of the language.

2
VBScripting
  • To include a control use input tags.
  • ltINPUT TYPEBUTTON NAMEcmdButton VALUE"Click
    Here"gt
  • To have VBScript recognized by the browser - use
    the following
  • ltSCRIPT LANGUAGE"VBScript"gt
  • lt!-- Use comment tag so that browsers that do not
    support VBScript will not print the code --gt
  • lt/SCRIPTgt

3
VBScripting contd.
  • To build the command button for the Input tag
  • ltSCRIPT LANGUAGE"VBScript"gt
  • lt!--
  • Sub cmdButton_OnClick
  • Msgbox Please enter a number from 1 to 10."
  • End Sub

4
Data - Variables Constants
  • Constant is data that will not change - fixed in
    value
  • Variable is data that can change during the
    course of the running of a program
  • Identifier is a name assigned to a variable or
    constant - memory is reserved for the variable /
    constant
  • Declaration statements define the variable /
    constant for the program

5
Declaration Statements
  • Const Identifier As Datatype Value
  • Const is a reserved word to define a constant in
    the declaration section
  • Dim Identifier As Datatype
  • A defaulted datatype becomes type variant
  • String values are called string literals
  • Intrinsic constants are VB built-in constants

6
Data Types
  • Boolean - True or False value (0 or 1)
  • Byte - A single ASCII character
  • Single Currency - Floating Point
  • Date - An eight character date
  • Double - Double precision floating point
  • Long Integer - Whole number
  • String - Alphanumeric characters
  • Variant - Stores any type

7
Local Declarations
  • The Dim statement can be placed anywhere within
    the local procedure
  • It is recommended to be placed at the top of the
    procedure
  • It must be placed before the variable is used
  • Variables and constants can be declared locally

8
Arithmetic Operators
  • The order of precedence is as follows
  • Exponentiation -
  • Multiplication and Division - , /
  • Addition and Subtraction - , -
  • Use parenthesis to change evaluation order of a
    mathematical expression
  • All evaluations occur from left to right
  • Parenthesis are performed first then in the order
    of precedence

9
Arrays
  • A series of items (Data Types) that are related
    to one another
  • They use the same name with an index to each part
    (element) of the array
  • They are similar to a control array except they
    are for data storage
  • The name tables or subscripted variables is
    sometimes used with them
  • The index is the subscript of the array

10
Dimensioning Arrays
  • The Dim statement is used similar to all other
    declarations
  • Dim Arrayname (lower To Upper) As Datatype
  • The lower subscript is not necessary - if left
    out the lower subscript will be zero
  • The datatype may be left out and defaults to
    variant
  • All data elements are initialized to zero for
    numerics and null string for strings

11
Dynamic Arrays
  • Arrays can be dimensioned dynamically
  • An array declared as - Dim Name() As Integer
  • Will allow redimensioning during program
    execution
  • The Redim statement is used to rediminsion an
    array
  • All other arrays are static arrays

12
Array Subscripts
  • The subscript used to reference into the array
    can be a constant
  • A literal number
  • A variable
  • A numeric expression
  • The subscript MUST reference a valid element of
    the array

13
Message Boxes
  • Message Boxes are used to notify the user of an
    error or display information
  • The message box can contain a message, icon,
    title bar caption or command button
  • MsgBox message ,buttons/icon, title bar
  • Displays the message centered in box
  • Displays title bar caption in the title bar

14
Message Box Buttons
  • vbOKOnly - 0 - Shows only the OK button
  • vbOkCancel - 1 - Shows the OK and Cancel buttons
  • vbAbortRetryIgnore - 2 - Shows the Abort, Retry
    and Ignore buttons
  • vbYesNoCancel - 3 - Shows the Yes, No and Cancel
    buttons
  • vbYesNo - 4 - Shows the Yes and No buttons
  • vbRertyCancel - 5 - Shows the Retry and Cancel
    buttons

15
Message Box Parameters
  • vbCritical - 16 - Uses a Critical X as an
    indicator
  • vbQuestion - 32 - Uses a Question mark as an
    indicator
  • vbExclamation - 48 - Uses a Exclamation point as
    an indicator
  • vbInformation - 64 - Uses an I as an indicator

16
Message Box Return Codes
  • vbOk -1 - Indicates an OK status
  • vbCancel - 2 - Indicates a return of cancel
  • vbAbort - 3 - Indicates a return of abort
  • vbRetry - 4 - Indicates a return of retry
  • vbIgnore - 5 - Indicates a return of Ignore
  • vbYes - 6 - Indicates a return of yes
  • vbNo - 7 - Indicates a return of No

17
Procedures / Functions
  • A sub procedure is code that performs a given
    operation, but does not return anything.
  • A function is code that performs a given
    operation and then returns a value to the caller.
    This value can be the result of some operation or
    just an error code.
  • The returned value is accomplished by using the
    name of the function and assigning a value.
  • To exit a sub procedure prematurely use Exit Sub.

18
Functions
  • Functions perform an action and return a value
    associated with that action
  • The VAL function will convert data into a numeric
    format
  • The Val function converts until the first
    non-numeric character is read

19
System Procedures
  • There are two types of system classes.
  • Events - a subroutine executed automatically by
    the system when a certain event takes place.
  • OnBlur - executed when an object is deselected
  • OnChange - executed when a user changes the
    object
  • OnClick - executed when an object is clicked
  • OnFocus - executed when an object is active (user
    selects)
  • Methods - controlled events. Methods normally are
    used to cause something to occur.
  • Calling a method is done by using the object name
    and the method name.
  • Objectname.Methodname

20
Conditional Statements
  • If ( condition) Then
  • statements
  • ElseIf (condition) Then
  • statements
  • Else
  • statements
  • End If
  • All data types must be of the same type

21
Relational Operators
  • The relational operators are used to compare two
    values - the result of the comparison is either
    True or False
  • gt - Greater than
  • lt - Less than
  • - Equal to
  • ltgt - not equal to
  • gt - Greater than or equal to
  • lt - Less than or equal to

22
Conditional Statements contd.
  • ASCII comparisons, handled left to right
  • All string literals must be enclosed in double
    quotes
  • Be careful using text boxes - their data type is
    variant
  • To check uppercase characters - Ucase()
  • To check lowercase characters - Lcase()
  • Use logical operators to test multiple conditions
    - Or , And , Not, Xor, Equ, Imp

23
Conditional statements contd.
  • Nested If Statements can be used, just remember
    to include the End If inside the nested If
  • The nesting can be accomplished in the Then
    portion of the condition, or in the Else portion
  • The ElseIf statement or an If within an If are
    both valid statements
  • It is highly recommended to flowchart conditional
    statements

24
Case Statements
  • Multiple If tests (nested or otherwise) can be
    replaced with the Case Statement
  • It is easier to read and easier to construct

25
Case Statement contd.
  • Select Case expression
  • Case Is relational expression
  • Statement
  • Case Constant To Constant
  • Statement
  • Case Else
  • Statement
  • End Select

26
Do Loops
  • Do Loops repeat instructions until a condition is
    met
  • Do While condition
  • statements to be repeated
  • Loop
  • Do
  • statements to be repeated
  • Loop Until condition

27
For / Next Loops
  • Used to allow repetitive operations in a sequence
    of code.
  • For LoopIndex Startvalue To EndValue Step
    Increment
  • statements to be repeated
  • Next LoopIndex
  • The Loop Index must be declared before entering
    the loop and the end value must be attainable.

28
For / Next Loops contd.
  • Once the end value has been reached the execution
    will drop out of the loop.
  • Negative numbers are allowed for the step value
  • Altering the values of the control variables will
    not affect the operation of the loop
Write a Comment
User Comments (0)
About PowerShow.com