VBScript - Tutorialspoint

Transcription

VBScriptAbout the TutorialMicrosoft VBScript (Visual Basic Script) is a general-purpose, lightweight and activescripting language developed by Microsoft that is modelled on Visual Basic. Nowadays,VBScript is the primary scripting language for Quick Test Professional (QTP), which is atest automation tool. This tutorial will teach you how to use VBScript in your day-to-daylife of any Web-based or automation project development.AudienceThis tutorial has been prepared for beginners to help them understand the basic-toadvanced functionality of VBScript. After completing this tutorial, you will find yourself ata moderate level of expertise in using Microsoft VBScript from where you can take yourselfto the next levels.PrerequisitesYou need to have a good understanding of any computer programming language in orderto make the most of this tutorial. If you have done programming in any client-sidelanguages like Javascript, then it will be quite easy for you to learn the ropes of VBScript.Copyright & Disclaimer Copyright 2015 by Tutorials Point (I) Pvt. Ltd.All the content and graphics published in this e-book are the property of Tutorials Point (I)Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute, or republishany contents or a part of contents of this e-book in any manner without written consentof the publisher.We strive to update the contents of our website and tutorials as timely and as precisely aspossible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt.Ltd. provides no guarantee regarding the accuracy, timeliness, or completeness of ourwebsite or its contents including this tutorial. If you discover any errors on our website orin this tutorial, please notify us at contact@tutorialspoint.comi

VBScriptTable of ContentsAbout the Tutorial . iAudience . iPrerequisites . iCopyright & Disclaimer . iPART 1: VBSCRIPT BASICS. 11.Overview . 2Features of VBScript . 2VBScript – Version History and Uses . 2Disadvantages. 2Where VBScript is Today? . 32.Syntax . 4Your First VBScript . 4Whitespace and Line Breaks . 4Formatting . 4Reserved Words . 5Case Sensitivity . 6Comments in VBScript . 73.Enabling VBScript in Browsers . 8VBScript in Internet Explorer . 84.Placements . 9VBScript Placement in HTML File . 9VBScript in head . /head section . 9VBScript in body . /body section . 10VBScript in body and head Sections . 10VBScript in External File . 11VBScript Placement in QTP . 125.Variables . 13VBScript Variables . 13Declaring Variables . 13Assigning Values to the Variables . 13Scope of the Variables . 146.Constants . 18Declaring Constants . 187.Operators. 20What is an Operator? . 20The Arithmetic Operators . 20The Comparison Operators . 22The Logical Operators . 25The Concatenation Operators . 278.Decision Making . 29If Statements . 30ii

VBScriptIf Else Statements . 31If.ElseIf.Else Statements . 33Nested If Statement . 35Switch Statements . 379.Loops . 39For Loops . 40For.Each Loops. 42While.Wend Loop . 44Do.While statement . 45Do.Until Loops . 49Loop Control Statements . 53Exit For statement . 53Exit Do statement . 5510. Events . 57What is an Event ? . 57onclick Event Type . 57onsubmit Event Type . 58onmouseover and onmouseout . 58HTML 4 Standard Events . 5911. VBScript and Cookies . 61What are Cookies?. 61How It Works? . 61Storing Cookies . 61Reading Cookies . 63Setting the Cookies Expiration Date . 64Deleting a Cookie . 6512. VBScript Numbers . 67Number Conversion Functions . 67Number Formatting Functions . 68Mathematical Functions . 7113. Strings . 75String Functions . 75InStr Function . 76InStrRev Function . 77LCase Function . 79UCase Function . 80Left Function .

VBScript is the primary scripting language for Quick Test Professional (QTP), which is a test automation tool. This tutorial will teach you how to use VBScript in your day-to-day life of any Web-based or automation project development. Audience This tutorial has been prepared for beginners to help them understand the basic-to-advanced functionality of VBScript. After completing this tutorial .