VBScript Session 2 Dani Vainstein.

Slides:



Advertisements
Similar presentations
1 VBScript Session What we learn last session?
Advertisements

Introduction to C Programming
Pemrograman VisualMinggu …7… Page 1 MINGGU Ke Tujuh Pemrograman Visual Pokok Bahasan: Arrays Tujuan Instruksional Khusus: Mahasiswa dapat menjelaskan.
 “Regular” variable ◦ Holds a single value ◦ For example Dim Student1 as String Dim Student2 as String Dim Student3 as String … Dim Studentn as String.
Case, Arrays, and Structures. Summary Slide  Case Structure –Select Case - Numeric Value Example 1 –Select Case - String Value Example  Arrays –Declaring.
Arrays Array of Controls: several controls, of the same type (Class: a prototype for an object indicating the properties and methods), that have the same.
Arrays Array of Controls: several controls, of the same type (Class: a prototype for an object indicating the properties and methods), that have the same.
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
Dani Vainstein1 VBScript Session 9. Dani Vainstein2 What we learn last session? VBScript coding conventions. Code convention usage for constants, variables,
IE 212: Computational Methods for Industrial Engineering
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Microsoft Visual Basic 2005 CHAPTER 9 Using Arrays and File Handling.
Multi-Dimensional Arrays
 2006 Pearson Education, Inc. All rights reserved Arrays.
Arrays and 2D Arrays.  A Variable Array stores a set of variables that each have the same name and are all of the same type.  Member/Element – variable.
© 2012 EMC Publishing, LLC Slide 1 Chapter 8 Arrays  Can store many of the same type of data together.  Allows a collection of related values to be stored.
Arrays Group of variables that have a similar type
Dani Vainstein1 VBScript Session 1. Dani Vainstein2 Subjets for Session 1 Vbscript fundamentals. Variant subtypes. Variables. Option Explicit statement.
‘Tirgul’ # 3 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #3.
Lab 6 (2) Arrays ► Lab 5 (1) Exercise Review ► Array Concept ► Why Arrays? ► Array Declaration ► An Example of Array ► Exercise.
Chapter 9 Processing Lists with Arrays. Class 9: Arrays Understand the concept of random numbers and how to generate random numbers Describe the similarities.
CHAPTER 9 PART II. MULTIDIMENSIONAL ARRAYS Used to represent tables of values arranged in rows and columns. Table element requires two indexes: row and.
CIVIL AND GEOMATIC ENGINEERING FT Okyere. CIV 257- COMPUTER PROGRAMMING Lecture 3.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Manipulating MATLAB Vector, Matrices 1. Variables and Arrays What are variables? You name the variables (as the programmer) and assign them numerical.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
Dani Vainstein1 VBScript Session 5. Dani Vainstein2 What we learn last session? Branching Branching using If … Then … Else statement. Branching using.
7.1 Introduction Arrays Arrays are data structures consisting of data items of the same type “Static” entities They remain the same size once they are.
Arrays and Collections
Programming Right from the Start with Visual Basic .NET 1/e
VBScript Session 1 Dani Vainstein.
VB Script V B S.
VBA - Excel VBA is Visual Basic for Applications
VBScript Session 1 IT Professional Academy.
EGR 2261 Unit 10 Two-dimensional Arrays
Computer Programming BCT 1113
Microsoft Visual Basic 2005: Reloaded Second Edition
IS 350 Arrays.
Collection in PL/SQL.
Visual Basic 2010 How to Program
Single Dimensional Arrays
2. Understanding VB Variables
Array processing and Matrix manipulation
JavaScript: Functions.
Chapter 10: Pointers 1.
Arrays, For loop While loop Do while loop
VBScript Session 2 Dani Vainstein.
VBScript Session 4 Dani Vainstein.
7 Arrays.
Lbound and Ubound Functions
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
Arrays 6-Dec-18.
VBScript Session 7 Dani Vainstein.
Object Oriented Programming in java
JavaScript Arrays.
MSIS 655 Advanced Business Applications Programming
Arrays.
Data Structures (CS212D) Week # 2: Arrays.
Arrays Week 2.
CIS16 Application Development and Programming using Visual Basic.net
7 Arrays.
EXCEL Creating An Array In VBA
EECE.2160 ECE Application Programming
Java SE 7 One and Multi Dimensional Arrays Module 6
VBScript Session 1.
Arrays 2-May-19.
EECE.2160 ECE Application Programming
Quick Test Professional Training Part 1
C++ Array 1.
Array processing and Matrix manipulation
Presentation transcript:

VBScript Session 2 Dani Vainstein

What we learn last session? Data types. Declaring, assigning and usage of variables. Option Explicit statement. VBScript keywords (Null,True …) Scope and liftime of variables. Rem statement. Dani Vainstein

Subjets for Session 2 Scalar variables and array variables. Redim statement. Preserve statement. Erase statement. Array function. LBound and UBound functions. Dani Vainstein

Scalar Variables and Array Variables Much of the time, you only want to assign a single value to a variable you have declared. A variable containing a single value is a scalar variable. Other times, it is convenient to assign more than one related value to a single variable. Then you can create a variable that can contain a series of values. This is called an array variable. Array variables and scalar variables are declared in the same way, except that the declaration of an array variable uses parentheses ( ) following the variable name. Dani Vainstein

Scalar Variables and Array Variables In the following example, a single-dimension array containing 11 elements is declared: Dim A(10) Although the number shown in the parentheses is 10, all arrays in VBScript are zero-based, so this array actually contains 11 elements. In a zero-based array, the number of array elements is always the number shown in parentheses plus one. This kind of array is called a fixed-size array. Dani Vainstein

Scalar Variables and Array Variables You assign data to each of the elements of the array using an index into the array. Beginning at zero and ending at 10, data can be assigned to the elements of an array as follows: A(0) = 256 A(1) = 324 A(2) = 100 . . . A(10) = 55 Similarly, the data can be retrieved from any element using an index into the particular array element you want. For example: SomeVariable = A(8) Dani Vainstein

Scalar Variables and Array Variables Arrays aren't limited to a single dimension. You can have as many as 60 dimensions, although most people can't comprehend more than three or four dimensions. You can declare multiple dimensions by separating an array's size numbers in the parentheses with commas. In the following example, the MyTeble variable is a two-dimensional array consisting of 6 rows and 11 columns: Dim MyTable(5, 10) Dani Vainstein

Scalar Variables and Array Variables In a two-dimensional array, the first number is always the number of rows; the second number is the number of columns. You can also declare an array whose size changes during the time your script is running. This is called a dynamic array. The array is initially declared within a procedure using either the Dim statement or using the Redim statement. Dani Vainstein

Arrays Redim Statement ReDim [Preserve] varname(subscripts) [, varname(subscripts)] . . . for a dynamic array, no size or number of dimensions is placed inside the parentheses. For example: Dim MyArray() To use a dynamic array, you must subsequently use ReDim to determine the number of dimensions and the size of each dimension. A subsequent ReDim statement resizes the array to 30, but uses the Preserve keyword to preserve the contents of the array as the resizing takes place. There is no limit to the number of times you can resize a dynamic array, although if you make an array smaller, you lose the data in the eliminated elements. Dani Vainstein

Arrays Redim Statement for a dynamic array, no size or number of dimensions is placed inside the parentheses. For example: Dim MyArray() To use a dynamic array, you must subsequently use ReDim to determine the number of dimensions and the size of each dimension. A subsequent ReDim statement resizes the array to 30, but uses the Preserve keyword to preserve the contents of the array as the resizing takes place. There is no limit to the number of times you can resize a dynamic array, although if you make an array smaller, you lose the data in the eliminated elements. Dani Vainstein

Preserve Statement Preserves the data in an existing array when you change the size of the last dimension. If you use the Preserve keyword, you can resize only the last array dimension, and you can't change the number of dimensions at all. For example, if your array has only one dimension, you can resize that dimension because it is the last and only dimension. However, if your array has two or more dimensions, you can change the size of only the last dimension and still preserve the contents of the array ReDim X(10, 10, 10) . . . ReDim Preserve X(10, 10, 15) Caution    If you make an array smaller than it was originally, data in the eliminated elements is lost. Dani Vainstein

Memory Dim a(5) Redim a(6) Redim preserve a(8) Dani Vainstein

Erase Statement Reinitializes the elements of fixed-size arrays and deallocates dynamic-array storage space. Erase array It is important to know whether an array is fixed-size (ordinary) or dynamic because Erase behaves differently depending on the type of array. Erase recovers no memory for fixed-size arrays. Erase sets the elements of a fixed array as follows: Fixed numeric array - Sets each element to zero. Fixed string array - Sets each element to zero-length (""). Array of objects - Sets each element to the special value Nothing. Dani Vainstein

Erase Statement Erase frees the memory used by dynamic arrays. Before your program can refer to the dynamic array again, it must redeclare the array variable's dimensions using a ReDim statement. Dani Vainstein

Array Function Returns a Variant containing an array. The required arglist argument is a comma-delimited list of values that are assigned to the elements of an array contained with the Variant. If no arguments are specified, an array of zero length is created. Dim A A = Array(10,20,30) Dani Vainstein

LBound Function LBound(arrayname[, dimension]) Returns the smallest available subscript for the indicated dimension of an array. The dimension argument means a whole number indicating which dimension's lower bound is returned. Use 1 for the first dimension, 2 for the second, and so on. If dimension is omitted, 1 is assumed The lower bound for any dimension is always 0. Dani Vainstein

UBound Function UBound(arrayname[, dimension]) Returns the largest available subscript for the indicated dimension of an array. The dimension argument means a whole number indicating which dimension's lower bound is returned. Use 1 for the first dimension, 2 for the second, and so on. If dimension is omitted, 1 is assumed The lower bound for any dimension is always 0. Dim A(100,3,4) UBound (A, 1) = 100 UBound (A, 2) = 3 UBound (A, 3) = 4 Dani Vainstein

Lab 2.1 Dani Vainstein

Lab 2.1 Write a small program Declare using Dim 2 array variables. arr1 – size of 5 arr2 – no size Assign descending values to arr1 (i.e. 5,4,3,2..0) Resize the first array to 10, no data loss Resize the second array to 5. Print the content of the arrays to the reporter. Dani Vainstein

Make sure to visit us Tutorials Articles Projects And much more www.AdvancedQTP.com