Chapter 6 Variables What is VBScript?

Slides:



Advertisements
Similar presentations
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Advertisements

Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Data Types and Operations Programming Fundamentals (Writing Code)Programming Fundamentals (Writing Code)
Chapter 2 Data Types, Declarations, and Displays
Chapter 2: Introduction to C++.
JavaScript, Third Edition
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Variables and Constants
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
1 VBA – podstawowe reguły języka Opracowanie Janusz Górczyński wg Microsoft Help.
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Dani Vainstein1 VBScript Session 1. Dani Vainstein2 Subjets for Session 1 Vbscript fundamentals. Variant subtypes. Variables. Option Explicit statement.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
INT213-Week-2 Working with Variables. What is variable
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
Dani Vainstein1 VBScript Session 3. Dani Vainstein2 What We learn Last seasson? How to declare arrays. Working with one dimensional a multi- dimensional.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Programming with Microsoft Visual Basic th Edition
CECS 5020 Computers in Education Visual Basic Variables and Constants.
Visual Basic CDA College Limassol Campus COM123 Visual Basic Programming Semester C Lecture:Pelekanou Olga Week 3: Using Variables.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
INT213 – WEEK 1 ASP tags and comments Variables, Constants, and "Literals" Simple Output.
A variable is a name for a value stored in memory.
VBScript Session 1 Dani Vainstein.
VB Script V B S.
VBScript Session 3.
Chapter 2 Variables.
Topics Designing a Program Input, Processing, and Output
Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology.
VBA - Excel VBA is Visual Basic for Applications
VBScript Session 1 IT Professional Academy.
Chapter 6 JavaScript: Introduction to Scripting
Chapter 2: Introduction to C++
BASIC ELEMENTS OF A COMPUTER PROGRAM
Visual Basic 6 (VB6) Data Types, And Operators
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Data Types, Arithmetic Operations
Multiple variables can be created in one declaration
Introduction to Scripting
JavaScript Syntax and Semantics
2. Understanding VB Variables
Lecture Set 4 Data Types and Variables
Chapter 2: Introduction to C++
Variables and Arithmetic Operations
2.1 Parts of a C++ Program.
CIS16 Application Development Programming with Visual Basic
Chapter 2 Variables.
PHP.
C++ Data Types Data Type
CHAPTER FOUR VARIABLES AND CONSTANTS
Chapter 2: Introduction to C++.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
VBScript Session 1.
Chapter 2 Variables.
Quick Test Professional Training Part 1
Variables and Constants
Presentation transcript:

Chapter 6 Variables What is VBScript? • VBScript is a scripting language • A scripting language is a lightweight programming language • VBScript is a light version of Microsoft's programming language Visual Basic How Does it Work? When a VBScript is inserted into a HTML document, the Internet browser will read the HTML and interpret the VBScript. The VBScript can be executed immediately, or at a later event. For those of you who have not used variables before, then you should know that the use of variables helps to make programs easier to program and to understand. Variables are used to hold information so that it can be reused throughout the program. Creating variables in vbscript as follows. Dim Myvar Dim total

Data types in vbscript. There are many different data types you might want to be able to store into variable: numbers, words, dates and many more. VBScript supports the following data types 1) Integer 2) Float 3) String 4) Date 5) Boolean 6) Currency 7) Object 8) Variant

Data types in vbscript Subtype Description Null Variant intentionally contains no valid data. Boolean Contains either True or False. Byte Contains integer in the range 0 to 255. Integer Contains integer in the range -32,768 to 32,767. Currency -922,337,203,685,477.5808 to 922,337,203,685,477.5807. Long Contains integer in the range -2,147,483,648 to 2,147,483,647.

Data types in vbscript Single Contains a single-precision, floating-point number in the range -3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values. Double Contains a double-precision, floating-point number in the range -1.79769313486232E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values. Date (Time) Contains a number that represents a date between January 1, 100 to December 31, 9999. String Contains a variable-length string that can be up to approximately 2 billion characters in length. Object Contains an object. Error Contains an error number.

Declaring variables There are two methods for declaring variables in VBScript, explicitly and implicitly. You usually declare variables explicitly with the Dim statement: Dim Name This statement declares the variable Name. You can also declare multiple variables on one line as shown below, although it is preferable to declare each variable separately: Dim Name, Address, City, State Variables can be declared implicitly by simply using the variable name within your script. This practice is not recommended. It leads to code that is prone to errors and more difficult to debug.

Declaring variables Variable Naming Rules When naming variables the following rules apply: They must begin with an alphabetic character They cannot contain embedded periods They must be unique within the same scope. They must be no longer than 255 characters

Declaring variables Scope of Variables The scope of a variable dictates where it can be used in your script. A variable's scope is determined by where it is declared. If it is declared within a procedure, it is referred to as a procedure-level variable and can only be used within that procedure. If it is declared outside of any procedure, it is a script-level variable and can be used throughout the script. The example below demonstrates both script-level and procedure-level variables. <SCRIPT>   Dim counter   Sub Abc1     Dim temp   End Sub </SCRIPT> The variable counter is a script-level variable and can be utilized throughout the script. The variable temp exists only within the Abc1 sub-procedure.

Option Explicit Option Explicit ' Force explicit variable declaration.   The Option Explicit statement forces the explicit declaration of all variables using the Dim, Private, Public, or ReDim statements.   In a long program, this statement prevents the accidental reuse of the name of a previously declared variable. Also, if you mistype a declared variable's name or try to use an undeclared variable, an error message is generated.   Note that the Option Explicit statement must be placed at the top of the code before any other VBScript commands or any HTML code.   Code: <% Option Explicit %> < HTML > < HEAD > < TITLE > EXAMPLE < /TITLE > < /HEAD > < BODY > <%   Dim myvariable,yourvar   myvariable = 123.456   yourvar = 0 %> < /BODY > < /HTML > Option Explicit ' Force explicit variable declaration. Dim MyVar ' Declare variable. MyInt = 10 ' Undeclared variable generates error. MyVar = 10 ' Declared variable does not generate error.

Arithmetic Operators Operator Description + Addition - Subtraction * Multiplication / Division \ Integer Division (divides two numbers and returns an integer result) Mod Modulus (remainder of a division) ^ Exponentiation (raises the number to the power of an exponent)

Comparison Operators Operator Description = Is equal to <> Is not equal to > Greater than >= Greater than or equal to < Less than <= Less than or equal to

Constants What Is a Constant? A constant is a meaningful name that takes the place of a number or string and never changes. VBScript defines a number of intrinsic constants. You can get information about these intrinsic constants from the VBScript Language Reference. Creating Constants You create user-defined constants in VBScript using the Const statement. Using the Const statement, you can create string or numeric constants with meaningful names and assign them literal values. For example: Const MyString = "This is my string." Const MyAge = 49 Note that the string literal is enclosed in quotation marks (" "). Quotation marks are the most obvious way to differentiate string values from numeric values. Date literals and time literals are represented by enclosing them in number signs (#). For example: Const CutoffDate = #6-1-97# You may want to adopt a naming scheme to differentiate constants from variables. This will prevent you from trying to reassign constant values while your script is running.

String Manipulation These functions allow you to manipulate string data. UCase(string) returns string with all lowercase letters converted to uppercase letters. LCase(string) returns string with all uppercase letters converted to lowercase letters. LTrim(string) removes all the spaces from the left side of string. RTrim(string) removes all the spaces from the right side of string. Trim(string) removes spaces from both the left and the right sides of string. Len(string) returns the number of characters in string. Len(variable) returns the number of bytes required by variable. LenB(string) returns the number of bytes required to store string. StrReverse(string) returns string with the characters in reverse order.

Arrays Arrays are the list of similar data items, which are stored in unique variable. Arrays may declared in two ways. Dim a a= Array( 1, 2,3 ….) Or Dim Myarray (3) Myarray(0)=1 Myarray(1)=2 . .so on.