{"id":20504,"date":"2024-07-20T05:38:46","date_gmt":"2024-07-20T05:38:46","guid":{"rendered":"https:\/\/www.softwaretestinghelp.com\/?p=20504"},"modified":"2025-05-09T10:57:15","modified_gmt":"2025-05-09T10:57:15","slug":"vbscript-tutorial-1","status":"publish","type":"post","link":"https:\/\/www.softwaretestinghelp.com\/vbscript-tutorial-1\/","title":{"rendered":"VBScript Tutorial for Beginners"},"content":{"rendered":"<p><strong>Introduction to Microsoft VBScript (Visual Basic Script):\u00a0VBScript Tutorial #1<br \/>\n<\/strong><\/p>\n<p>In today&#8217;s scenario, VBScript has turned out to be a very important topic, especially for beginners who wish to learn the scripting language or automation tools like QTP\/UFT.<\/p>\n<p><strong>=&gt;\u00a0<a href=\"https:\/\/www.softwaretestinghelp.com\/qtp-quicktest-professional-tutorial-1\/\">Click Here For The QTP Training Tutorials Series<\/a><\/strong><\/p>\n<p><strong>=&gt; <span style=\"color: #ff6600;\">SCROLL DOWN to see the complete list of 15+ In-Depth VBScript Tutorials for Beginners<\/span><\/strong><\/p>\n<p>We will be covering a series of VB Scripting tutorials to help developers and testers learn VBScript quickly in an easily understandable way.  <\/p>\n<h2>Learning VBScript From Scratch<\/h2>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-21140\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/01\/VBscript-tutorial.jpg\" alt=\"VBscript tutorial\" width=\"560\" height=\"274\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/01\/VBscript-tutorial.jpg 560w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/01\/VBscript-tutorial-300x147.jpg 300w\" sizes=\"(max-width: 560px) 100vw, 560px\" \/><\/p>\n<p>In my subsequent tutorials, I will cover other important topics of VBScript like Variables, Constants, Operators, Arrays, Functions, Procedures, Excel Objects, Connections Objects, etc., which in turn will create an easy understanding among the users for learning VBScript Programming Language easily and effectively.<\/p>\n<p>***************************************************************<\/p>\n<p><span style=\"color: #ff0000;\"><strong>==&gt; Learn VBScript with these 15 Tutorials\u00a0 &lt;==<\/strong><\/span><\/p>\n<p><strong><span style=\"text-decoration: underline;\">Tutorial #1<\/span>: <\/strong><a href=\"https:\/\/www.softwaretestinghelp.com\/vbscript-tutorial-1\/\">Introduction to VBScript<\/a><br \/>\n<strong><span style=\"text-decoration: underline;\">Tutorial #2<\/span>: <\/strong><a href=\"https:\/\/www.softwaretestinghelp.com\/vbscript-variables-tutorial-2\/\">Declaring and Using Variables in VBScript<\/a><br \/>\n<strong><span style=\"text-decoration: underline;\">Tutorial #3<\/span>: <\/strong><a href=\"https:\/\/www.softwaretestinghelp.com\/vbscript-constants-and-operators-tutorial-3\/\">Operators, Operator Precedence and Constants in VBScript<\/a><br \/>\n<strong><span style=\"text-decoration: underline;\">Tutorial #4<\/span>: <\/strong><a href=\"https:\/\/www.softwaretestinghelp.com\/vbscript-conditional-statements-tutorial-4\/\">Using Conditional Statements in VBScript<\/a><br \/>\n<strong><span style=\"text-decoration: underline;\">Tutorial #5<\/span>: <\/strong><a href=\"https:\/\/www.softwaretestinghelp.com\/vbscript-loops-tutorial-5\/\">Loops in VBScript and<\/a> also <a href=\"https:\/\/www.softwaretestinghelp.com\/qtp-tutorial-10-vb-script-basics-part2\/\" target=\"_blank\" rel=\"noopener\">Part 2 here<\/a><br \/>\n<strong><span style=\"text-decoration: underline;\">Tutorial #6<\/span>: <\/strong><a href=\"https:\/\/www.softwaretestinghelp.com\/vbscript-procedures-functions-tutorial-6\/\">Using Procedures and Functions in VBScript<\/a><br \/>\n<strong><span style=\"text-decoration: underline;\">Tutorial #7<\/span>: <\/strong><a href=\"https:\/\/www.softwaretestinghelp.com\/vbscript-arrays-tutorial-7\/\">Arrays in VBScript<\/a><br \/>\n<strong><span style=\"text-decoration: underline;\">Tutorial #8<\/span>: <\/strong><a href=\"https:\/\/www.softwaretestinghelp.com\/vbscript-date-functions-tutorial-8\/\">Date Functions in VBScript<\/a><br \/>\n<strong><span style=\"text-decoration: underline;\">Tutorial #9<\/span>: <\/strong><a href=\"https:\/\/www.softwaretestinghelp.com\/vbscript-string-functions-instr-replace-tutorial-9\/\">Working with Strings and Cookies in VBScript<\/a><br \/>\n<strong><span style=\"text-decoration: underline;\">Tutorial #10<\/span>: <\/strong><a href=\"https:\/\/www.softwaretestinghelp.com\/vbscript-events-tutorial-10\/\">Working with Events in VBScript<\/a><br \/>\n<strong><span style=\"text-decoration: underline;\">Tutorial #11<\/span>: <\/strong><a href=\"https:\/\/www.softwaretestinghelp.com\/vbscript-excel-tutorial-11\/\">Working with Excel Objects in VBScript<\/a><br \/>\n<strong><span style=\"text-decoration: underline;\">Tutorial #12<\/span>: <\/strong><a href=\"https:\/\/www.softwaretestinghelp.com\/vbscript-connection-objects-tutorial-12\/\">Working with Connection Objects in VBScript<\/a><br \/>\n<strong><span style=\"text-decoration: underline;\">Tutorial #13<\/span>:<\/strong> <a href=\"https:\/\/www.softwaretestinghelp.com\/vbscript-files-tutorial-13\/\">Working with Files in VBScript<\/a><br \/>\n<strong><span style=\"text-decoration: underline;\">Tutorial #14<\/span>: <\/strong><a href=\"https:\/\/www.softwaretestinghelp.com\/vbscript-error-handling-tutorial-14\/\">Error Handling in VBScript<\/a><br \/>\n<strong><span style=\"text-decoration: underline;\">Tutorial #15<\/span>: <\/strong><a href=\"https:\/\/www.softwaretestinghelp.com\/popular-vbscript-interview-questions-answers\/\">VBScript Interview Questions<\/a><\/p>\n<p>***************************************************************<\/p>\n<p>Initially, to start with, I have chosen the first topic as <strong><em>&#8220;Introduction to VBScript&#8221;.<\/em><\/strong><\/p>\n<p><em><strong>In this tutorial, I will discuss the basics of VBScript, thereby focusing more on its features, data types supported by it and coding methodologies along with the procedure to handle comments and formats in scripts<\/strong>.<\/em><\/p>\n<h3>What is VBScript?<\/h3>\n<p>As the name itself explains, <strong>VBScript is a &#8220;Scripting Language&#8221;<\/strong>. It is a lightweight case insensitive programming language developed by Microsoft. It is a subset of &#8220;Visual Basic&#8221; or we may also say it as a lighter version of Microsoft\u2019s programming language, Visual Basic.<\/p>\n<p>Most of us would have used Visual Basic during our course curriculum in our school or college. Visual Basic is an event-driven programming language and an Integrated Development Environment from Microsoft.<\/p>\n<p>VBScript language is used in QTP for coding and running Automated Test Scripts. This is not a very difficult language to learn and with a little knowledge of basic programming skills and passion for writing code, anyone can learn this easily. For those who know Visual Basic, it is an added advantage.<\/p>\n<p>Automation Testers, who want to create, maintain and execute the tests in QTP need to have basic programming skills using VBScript.<\/p>\n<h3>Basics of VB Scripting Concepts<\/h3>\n<p><span style=\"color: #ff9900;\"><strong><em>Now let\u2019s move on to some basic topics that are revolving around VBScript to enable clear understanding and knowledge about VBScript.<\/em><\/strong><\/span><\/p>\n<h4>Data types<\/h4>\n<p>1) There is only one data type: <b>Variant<\/b>. It can store different kinds of information based on the context in which it is used.<br \/>\n2) If used in a numeric context it is a number or a string if used in a string expression.<br \/>\n3) If a number has to behave as a string, we could enclose it within \u201c \u201c.<br \/>\n4) There are various subtypes to a variant. You can explicitly specify these subtypes to achieve a clear definition for your data. Below is a screenshot from the VB User guide that shows all the subtypes of data that can be used:<br \/>\n<em>(click on the image to expand)<\/em><\/p>\n<p><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2013\/04\/VB-script-data-types.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-1675\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2013\/04\/VB-script-data-types.jpg\" alt=\"VB script data types\" width=\"494\" height=\"327\" \/><\/a><\/p>\n<p>5) Conversion functions can be used to convert one subtype of data into another.<br \/>\n6) Since it is the only data type available, all the return values from a function are variants.<\/p>\n<p>Here are a few different VBScripting <a href=\"https:\/\/www.w3schools.com\/asp\/asp_examples.asp\" target=\"_blank\" rel=\"noopener nofollow\">examples<\/a> you can try on your own.<\/p>\n<h4><b>Variables<\/b><\/h4>\n<p><strong>1)<\/strong> A variable is nothing but a space in the computer\u2019s memory that can store certain information. This information is bound to change from time to time. Where the information goes physically is immaterial but when needed, it can be accessed or changed by addressing the name of the variable.<\/p>\n<p><span style=\"text-decoration: underline;\">E.g., if<\/span> there is a statement that you want to run several times, you could use a variable to contain that count. Say X. X is a variable that can be used to store, change and use the space in the memory where we want to keep the count.<\/p>\n<p><strong>2)<\/strong> All variables are of the Datatype Variant.<\/p>\n<p><strong>3)<\/strong> Declaring a variable before its use is optional, although it\u2019s a good practice to do so.<\/p>\n<p><strong>4)<\/strong> To make the declaration mandatory, there is an \u201c<b>Option Explicit\u201d <\/b>Statement available. To declare variables:<\/p>\n<p>Dim x \u2013 This declares\u00a0 x<br \/>\nDim x, y, z \u2013 This declares multiple variables.<br \/>\nX=10 \u2013 This is how a value is assigned. As a general rule, the variable is the left-hand side component and the right is its value.<br \/>\nX=\u201dSwati\u201d \u2013 this is the way a string value is assigned.<\/p>\n<p>To make declarations mandatory this is how the code has to be written:<br \/>\n<i>Option Explicit<\/i><br \/>\n<i>Dim x, stri<\/i><\/p>\n<p>If Option&#8217;s explicit statement was not used, we could have directly written:<br \/>\n<i>x=100<\/i><br \/>\n<i>stri=\u201dSwati\u201d<\/i><br \/>\nand it would not have thrown an error.<\/p>\n<p><strong>5)<\/strong> <b>Naming convention<\/b>: Names must start with an alphabetic character, must be unique, cannot contain an\u00a0embedded period and cannot exceed 255 chars.<\/p>\n<p><strong>6)<\/strong> A variable containing a single value is a scalar variable and the one that has more than one is an array.<\/p>\n<p><strong>7)<\/strong> A one dimensional Array can be declared as Dim A(10). All the arrays in the VB Script are zero-based which means the array index starts from 0 through the number declared. This means that our array A has 11 elements. Starting from 0 to 10.<\/p>\n<p><strong>8)<\/strong> To declare a 2-dimensional array simply separate the row count and column count by a comma. Eg: Dim A(5, 3). This means it has 6 rows and 4 columns. The first number is always row and the second is a comma.<\/p>\n<p><strong>9)<\/strong> There is also a dynamic array whose size can change during runtime.\u00a0 These arrays can be declared using dim or redim statements.<\/p>\n<p>If an array is declared as Dim A(10) and during runtime, if we need more space we can do the same by using the statement: redim A(10). There is a \u201cPreserve\u201d statement that can be used in conjunction with the redim statement.<\/p>\n<p>Dim A(10,10)<br \/>\n\u2026\u2026<br \/>\n\u2026.<br \/>\nRedim preserve A(10,20)<\/p>\n<p>This piece of code shows how we do it. Initially, A is an 11 by 11 array. Then we are resizing it to be an 11 by 21 array and the preserve statement will make sure that the data that is previously contained in the array is not lost.<\/p>\n<h4><b>Constants<\/b><\/h4>\n<ol>\n<li>As the name implies, a constant is nothing but an unchanging value in a program that is assigned a name.<\/li>\n<li>They can be declared by prefixing \u201cConst\u201d to a name.<\/li>\n<li>Eg: Const a=\u201d10\u201d or Const Astr=\u201dSwati\u201d.<\/li>\n<li>This value cannot be changed accidentally while the script is running.<\/li>\n<\/ol>\n<h4><b>Operators<\/b><\/h4>\n<p>Some of the most important operators that are most commonly used are:<\/p>\n<ol>\n<li>String concatenation: &amp; (Eg: Dim x=\u201dgood\u201d&amp;\u201dday\u201d, so x contains \u201cgoodday\u201d<\/li>\n<li>Addition (+)<\/li>\n<li>Subtraction (-)<\/li>\n<li>Multiplication (*)<\/li>\n<li>Division(\/)<\/li>\n<li>Logical negation (Not)<\/li>\n<li>Logical conjunction (And)<\/li>\n<li>Logical Disjunction (Or)<\/li>\n<li>Equality(=)<\/li>\n<li>Inequality (&lt;&gt;)<\/li>\n<li>Less than (&lt;)<\/li>\n<li>Greater than(&gt;)<\/li>\n<li>Less than or equal to(&lt;=)<\/li>\n<li>Greater than or equal to (&gt;=)<\/li>\n<li>Object Equivalence (Is)<\/li>\n<\/ol>\n<p>It is important to note that the list is not complete but merely a subset containing the most commonly used operators.<\/p>\n<p><strong>The operator precedence rules are:<\/strong><\/p>\n<ol>\n<li>Multiplication or Division takes precedence over addition or subtraction<\/li>\n<li>If multiplication and division exist in the same expression, then left to right order is considered<\/li>\n<li>If Addition and subtraction occur in the same expression, then too, the left and the right order is taken into consideration.<\/li>\n<li>The order can be overridden by using parenthesis. In this case, the expression within the parenthesis is executed first.<\/li>\n<li>&amp; operator takes precedence after all arithmetic operators and before all logical operators.<\/li>\n<\/ol>\n<h3>Environments that Support VBScript<\/h3>\n<p>Primarily, there are 3 environments where VBScript can be run.<\/p>\n<p><strong><span style=\"color: #ff9900;\">They include:<\/span><\/strong><\/p>\n<p><strong>#1) IIS (Internet Information Server):<\/strong> <strong>I<\/strong>nternet <strong>I<\/strong>nformation <strong>S<\/strong>erver is Microsoft&#8217;s Web Server.<\/p>\n<p><strong>#2) WSH (Windows Script Host):\u00a0W<\/strong>indows <strong>S<\/strong>cript <strong>H<\/strong>ost is the hosting environment of the Windows Operating System.<\/p>\n<p><strong>#3) IE (Internet Explorer):\u00a0I<\/strong>nternet <strong>E<\/strong>xplorer is the simple hosting environment that is most frequently used to run scripts.<\/p>\n<h3>Data Types in VBScript<\/h3>\n<p>Unlike other languages, VBScript has only 1 data type called <strong>Variant<\/strong>.<\/p>\n<p>As this is the only data type that is used in VBScript, it\u2019s the only data type that is returned by all the functions in the VBScript.<\/p>\n<p>A variant data type can contain different kinds of information, depending on how it is used. <em><strong><span style=\"text-decoration: underline;\">For example, if<\/span><\/strong><\/em> we use this data type in the String context then this will behave like a String and if we use it in the Numeric context then it will behave like a Number. This is the specialty of a Variant data type.<\/p>\n<p>Variant data types can contain several subtypes. Now, let&#8217;s take a look at what all values\/data will be returned if a particular subtype is used.<\/p>\n<p><strong>Subtypes include:<\/strong><\/p>\n<p><span style=\"color: #ff9900;\"><strong>#1) Empty:<\/strong><\/span> This subtype indicates that the value will be 0 in the case of Numeric Variables and \u201cfor String Variables.<\/p>\n<p><span style=\"color: #ff9900;\"><strong>#2) Null: <\/strong><\/span>This subtype indicates that there is no valid data.<\/p>\n<p><span style=\"color: #ff9900;\"><strong>#3) Boolean: <\/strong><\/span>This subtype indicates that the resultant value will be either true or false.<\/p>\n<p><span style=\"color: #ff9900;\"><strong>#4) Byte: <\/strong><\/span>This subtype exhibits that the resultant value will lie in the range between 0 to 255 i.e. the result will be from any value ranging from 0 to 255.<\/p>\n<p><span style=\"color: #ff9900;\"><strong>#5) Integer: <\/strong><\/span>This subtype shows that the resultant value will lie in the range between -32768 to 32767 i.e. the result will be from any value ranging from -32768 to 32767<\/p>\n<p><span style=\"color: #ff9900;\"><strong>#6) Currency: <\/strong><\/span>This subtype indicates that the resultant value will lie in the range between -922,337,203,685,477.5808 to 922,337,203,685,477.5807 i.e. the result will be from any value ranging from -327-922,337,203,685,477.5808 to 922,337,203,685,477.5807.<\/p>\n<p><span style=\"color: #ff9900;\"><strong>#7) Long: <\/strong><\/span>This subtype shows that the resultant value will lie in the range from -2,147,483,648 to 2,147,483,647 i.e. The results will range from any value in between -2,147,483,648 to 2,147,483,647.<\/p>\n<p><span style=\"color: #ff9900;\"><strong>#8) Single: <\/strong><\/span>This subtype exhibits that the resultant value will be from any value between -3.402823E38 to -1.401298E-45 in case of negative values.<\/p>\n<p>And for positive values, the result will be from any value between 1.401298E-45 to 3.402823E38.<\/p>\n<p><span style=\"color: #ff9900;\"><strong>#9) Double: <\/strong><\/span>This subtype indicates that the resultant value will be from any value between -1.79769313486232E308 to 4.94065645841247E-324 in case of negative values.<\/p>\n<p>And for positive values, the result will be from any value between 4.94065645841247E-324 to 1.79769313486232E308.<\/p>\n<p><span style=\"color: #ff9900;\"><strong>#10) Date (Time): <\/strong><\/span>This subtype will return a number that will represent the date value between January 1, 100 to December 31, 9999<\/p>\n<p><span style=\"color: #ff9900;\"><strong>#11) String: <\/strong><\/span>This subtype will return a variable-length string value which can approximately be up to 2 billion characters in length.<\/p>\n<p><span style=\"color: #ff9900;\"><strong>#12) Object: <\/strong><\/span>This subtype will return an object.<\/p>\n<p><span style=\"color: #ff9900;\"><strong>#13) Error: <\/strong><\/span>This subtype will return an error number.<\/p>\n<h3>How to Create a Simple VBScript?<\/h3>\n<p>To create a VBScript, there are only 2 things required.<\/p>\n<p><span style=\"color: #ff9900;\"><strong>They are:<\/strong><\/span><\/p>\n<ul>\n<li><strong>Text Editors<\/strong> like Notepad++ or even Notepad to write the VBScript Code.<\/li>\n<li><strong>IE<\/strong> (good to have IE6 or above) to run the VBScript Code.<\/li>\n<\/ul>\n<p>Now, let\u2019s look at a few VBScript codes for clarity purposes, but before that, it is important to know where the Scripts can be inserted in an HTML Page.<\/p>\n<h3>Where to Insert Scripts in an HTML Page?<\/h3>\n<p>VBScript provides you with the liberty to place a code in any of the following sections:<\/p>\n<ul>\n<li><span style=\"color: #000000;\"><strong>Within the Header Tags<\/strong><\/span> i.e. in between &lt;head&gt; and &lt;\/head&gt;.<\/li>\n<li><span style=\"color: #000000;\"><strong>Within the Document\u2019s Body<\/strong><\/span> i.e. between &lt;body&gt; and &lt;\/body&gt; tags.<\/li>\n<\/ul>\n<p><span style=\"color: #ff9900;\"><strong>First VBScript Code in HTML:<\/strong><\/span><\/p>\n<p><em><strong>Now, let\u2019s take a simple example to understand how VBScript code can be written inside HTML tags.<\/strong><\/em><\/p>\n<pre>&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;title&gt; Testing VBScript Skills &lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;script type=\u201dtext\/vbscript\u201d&gt;\r\nvariable1 = 1\r\nvariable2 = 2\r\noutput = (variable1 + variable2) \/ 1\r\ndocument.write (\u201cresultant from the above equation is \u201d &amp; output)\r\n&lt;\/script&gt; \r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><span style=\"color: #ff9900;\"><strong>Note<\/strong>:<\/span> Whatever is put inside the brackets of a document. write\u2019, will be displayed as an output on the display page.<\/p>\n<p><strong>The output<\/strong> of this program is: <strong>resultant from the above equation is 3<\/strong><\/p>\n<p>After completing the code, you can save this in a file and give the file name as anyfilename.html.<\/p>\n<p><strong>To run it<\/strong>, just open this file in IE.<\/p>\n<p><strong><span style=\"color: #ff6600;\">Important to Know:<\/span> <\/strong><\/p>\n<p>We have just seen the implementation of VBScript code in the HTML file. <strong>However, VBScript in QTP is not placed inside the HTML tags. It is saved with an extension \u2018.vbs\u2019 and is executed by the QTP Execution Engine.<\/strong><\/p>\n<p>To understand the practical implementation of VBScript in terms of QTP, you must know variables, constants, etc. I will cover that in my upcoming tutorials for the time being, I just want to show you the VBScript code with the concept of an external file.<\/p>\n<p><span style=\"color: #ff6600;\"><strong>VBScript in External File:<\/strong><\/span><\/p>\n<pre>&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;script type=\u201dtext\/vbscript\u201d src=\u201dnameofthefile.vbs\u201d&gt; &lt;\/script&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\nvariable1 = 22\r\nvariable2 = 21\r\nsubtraction = variable1 - variable2\r\ndocument.write (\u201csubtraction of 2 numbers is\u201d &amp; subtraction)\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><strong>To access this code from an external source, save this code in a text file with the extension \u201c.vbs\u201d.<\/strong><\/p>\n<h3>How Comments are Handled in VBScript<\/h3>\n<p>It is considered to be a good programming practice to include comments in the Scripts for better readability and understanding purposes.<\/p>\n<p><strong>There are 2 ways in which Comments can be handled in a VBScript:<\/strong><\/p>\n<p><span style=\"color: #ff9900;\"><strong>#1) Any Statement that starts with a Single Quote (\u2018) is treated as a comment:<\/strong><\/span><\/p>\n<pre>&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;script type=\u201dtext\/vbscript\u201d&lt;\/script&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\u2018let\u2019s do subtraction of 2 numbers \r\nvariable1 = 11\r\nvariable2 = 10\r\nsubtraction = variable1 - variable2\r\ndocument.write (\u201csubtraction of 2 numbers is\u201d &amp; subtraction)\r\n&lt;\/body&gt;\r\n&lt;\/html\r\n\r\n<a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/01\/Single-Quote.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-21004\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/01\/Single-Quote.jpg\" alt=\"Single Quote\" width=\"453\" height=\"297\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/01\/Single-Quote.jpg 453w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/01\/Single-Quote-300x197.jpg 300w\" sizes=\"(max-width: 453px) 100vw, 453px\" \/><\/a><\/pre>\n<p><span style=\"color: #ff9900;\"><strong>#2)<\/strong> <strong>Any Statements that start with the keyword REM are treated as Comments.<\/strong><\/span><\/p>\n<pre>&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;script type=\u201dtext\/vbscript\u201d&gt;&lt;\/script&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n<strong>REM let\u2019s do subtraction of 2 numbers\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/strong>\r\nvariable1 = 11\r\nvariable2 = 10\r\nsubtraction = variable1 - variable2\r\ndocument.write (\u201csubtraction of 2 numbers is\u201d &amp; subtraction)\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/01\/REM-1.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-21012\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/01\/REM-1.jpg\" alt=\"REM\" width=\"447\" height=\"305\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/01\/REM-1.jpg 447w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/01\/REM-1-300x205.jpg 300w\" sizes=\"(max-width: 447px) 100vw, 447px\" \/><\/a><\/p>\n<p><strong><span style=\"color: #ff9900;\">Formatting Tips:<\/span><\/strong><\/p>\n<p><strong>#1)<\/strong> No Semicolon is required to end this particular statement in VBScript.<\/p>\n<p><strong>#2)<\/strong> If 2 or more lines are written in the same line in VBScript then<strong> Colons (:) act as a line separator<\/strong>.<\/p>\n<p><span style=\"color: #003366;\"><strong>Let\u2019s understand this with the help of an Example:<\/strong><\/span><\/p>\n<pre>&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;script type=\u201dtext\/vbscript\u201d&gt;&lt;\/script&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n<strong>variable1 = 11:variable2 = 21:variable3=34<\/strong>\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><strong><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/01\/Formatting-Tips.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-21005\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/01\/Formatting-Tips.jpg\" alt=\"Formatting Tips\" width=\"513\" height=\"206\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/01\/Formatting-Tips.jpg 513w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/01\/Formatting-Tips-300x120.jpg 300w\" sizes=\"(max-width: 513px) 100vw, 513px\" \/><\/a><br \/>\n#3)<\/strong> If a statement is lengthy and required to break into multiple statements then you can use the <strong>underscore<\/strong> \u201c_\u201d.<\/p>\n<p><span style=\"text-decoration: underline;\"><em><strong>Let\u2019s see its Example:<\/strong><\/em><\/span><\/p>\n<pre>&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;script type=\u201dtext\/vbscript\u201d&gt;&lt;\/script&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\nvariable1 = 11\r\nvariable2 = 10\r\noutput = (variable1 - variable2) * 10\r\ndocument.write (\u201coutput generated from the calculation\u201d&amp; _\r\n\u201cof using variable1 and variable2 with the multiplication of resultant\u201d&amp;_\r\nfrom 10 is\u201d &amp; output)\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/01\/Underscore.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-20576\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/01\/Underscore.jpg\" alt=\"Underscore\" width=\"603\" height=\"324\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/01\/Underscore.jpg 603w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2018\/01\/Underscore-300x161.jpg 300w\" sizes=\"(max-width: 603px) 100vw, 603px\" \/><\/a><\/p>\n<h3>Reserved Keywords<\/h3>\n<p>In any language, there are a set of words that work as Reserved Words and they cannot be used as Variable names, Constant names, or any other Identifier names.<\/p>\n<p><strong><span style=\"color: #ff6600;\">The following is the list of Reserved Keywords in VBScript:<\/span><\/strong><\/p>\n\n<div id=\"tablepress-186-scroll-wrapper\" class=\"tablepress-scroll-wrapper\">\n<table id=\"tablepress-186\" class=\"tablepress tablepress-id-186 tablepress-responsive\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">Loop<\/th><th class=\"column-2\">New<\/th><th class=\"column-3\">Null<\/th><th class=\"column-4\">ParamArray<br \/>\n<br \/>\n<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\">LSet<\/td><td class=\"column-2\">Next<\/td><td class=\"column-3\">On<\/td><td class=\"column-4\">Preserve<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\">Me<\/td><td class=\"column-2\">Nothing<\/td><td class=\"column-3\">Option<\/td><td class=\"column-4\">Private<\/td>\n<\/tr>\n<tr class=\"row-4\">\n\t<td class=\"column-1\">Mod<\/td><td class=\"column-2\">Not<\/td><td class=\"column-3\">Optional<\/td><td class=\"column-4\">Public<\/td>\n<\/tr>\n<tr class=\"row-5\">\n\t<td class=\"column-1\">RaiseEvent<\/td><td class=\"column-2\">ReDim<\/td><td class=\"column-3\">Dem<\/td><td class=\"column-4\">Rem<\/td>\n<\/tr>\n<tr class=\"row-6\">\n\t<td class=\"column-1\">Resume<\/td><td class=\"column-2\">RSet<\/td><td class=\"column-3\">Select<\/td><td class=\"column-4\">Set<\/td>\n<\/tr>\n<tr class=\"row-7\">\n\t<td class=\"column-1\">Shared<\/td><td class=\"column-2\">Single<\/td><td class=\"column-3\">Static<\/td><td class=\"column-4\">Stop<\/td>\n<\/tr>\n<tr class=\"row-8\">\n\t<td class=\"column-1\">Sub<\/td><td class=\"column-2\">Then<\/td><td class=\"column-3\">To<\/td><td class=\"column-4\">True<\/td>\n<\/tr>\n<tr class=\"row-9\">\n\t<td class=\"column-1\">Type<\/td><td class=\"column-2\">And<\/td><td class=\"column-3\">As<\/td><td class=\"column-4\">Boolean<\/td>\n<\/tr>\n<tr class=\"row-10\">\n\t<td class=\"column-1\">Case<\/td><td class=\"column-2\">Class<\/td><td class=\"column-3\">Const<\/td><td class=\"column-4\">Currency<\/td>\n<\/tr>\n<tr class=\"row-11\">\n\t<td class=\"column-1\">Debug<\/td><td class=\"column-2\">Dim<\/td><td class=\"column-3\">Do<\/td><td class=\"column-4\">Double<\/td>\n<\/tr>\n<tr class=\"row-12\">\n\t<td class=\"column-1\">Each<\/td><td class=\"column-2\">Else<\/td><td class=\"column-3\">Elself<\/td><td class=\"column-4\">Empty<\/td>\n<\/tr>\n<tr class=\"row-13\">\n\t<td class=\"column-1\">Event<\/td><td class=\"column-2\">Exit<\/td><td class=\"column-3\">False<\/td><td class=\"column-4\">For<\/td>\n<\/tr>\n<tr class=\"row-14\">\n\t<td class=\"column-1\">Function<\/td><td class=\"column-2\">GoTo<\/td><td class=\"column-3\">If<\/td><td class=\"column-4\">Imp<\/td>\n<\/tr>\n<tr class=\"row-15\">\n\t<td class=\"column-1\">Implements<\/td><td class=\"column-2\">In<\/td><td class=\"column-3\">Integer<\/td><td class=\"column-4\">Is<\/td>\n<\/tr>\n<tr class=\"row-16\">\n\t<td class=\"column-1\">Until <\/td><td class=\"column-2\">Variant<\/td><td class=\"column-3\">Wend<\/td><td class=\"column-4\">While<\/td>\n<\/tr>\n<tr class=\"row-17\">\n\t<td class=\"column-1\">With<\/td><td class=\"column-2\">Xor<\/td><td class=\"column-3\">Eval<\/td><td class=\"column-4\">Execute<\/td>\n<\/tr>\n<tr class=\"row-18\">\n\t<td class=\"column-1\">MsgBox<\/td><td class=\"column-2\">Erase<\/td><td class=\"column-3\">ExecuteGlobal<\/td><td class=\"column-4\">Option<\/td>\n<\/tr>\n<tr class=\"row-19\">\n\t<td class=\"column-1\">OptionExplicit<\/td><td class=\"column-2\">Randomize<\/td><td class=\"column-3\">SendKeys<\/td><td class=\"column-4\">Let<\/td>\n<\/tr>\n<tr class=\"row-20\">\n\t<td class=\"column-1\">Let<\/td><td class=\"column-2\">Like <\/td><td class=\"column-3\">Long<\/td><td class=\"column-4\">Type<\/td>\n<\/tr>\n<tr class=\"row-21\">\n\t<td class=\"column-1\">End<\/td><td class=\"column-2\">EndIf<\/td><td class=\"column-3\">Enum<\/td><td class=\"column-4\">Eqv<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<!-- #tablepress-186 from cache -->\n<h3>Conclusion<\/h3>\n<p>That&#8217;s it! This is all about the basic concepts that are involved in VBScript.<\/p>\n<p>I hope that this VBScript tutorial will give you a brief overview and a clear understanding of the scripting language with easy examples.<\/p>\n<p><em><strong>About the author:<\/strong> Thanks to STH Team member Varsha for helping us compile this <\/em>series<em>. She is in the Software Testing field with core VBScripting skills and <\/em>has received<em> many internal excellence awards.<\/em><\/p>\n<p><em><strong><a href=\"https:\/\/www.softwaretestinghelp.com\/vbscript-variables-tutorial-2\/\">NEXT Tutorial #2<\/a> =&gt; In my upcoming VBS tutorial, I will cover Variables in VBScript.<\/strong><\/em><\/p>\n<p><strong>=&gt;\u00a0<a href=\"https:\/\/www.softwaretestinghelp.com\/qtp-quicktest-professional-tutorial-1\/\">Visit Here For The QTP Training Tutorials Series<\/a><\/strong><\/p>\n<p><em><strong>Stay tuned for more updates, and feel free to share your thoughts about this tutorial.<br \/>\n<\/strong><\/em><\/p>\n\r\n\t\t\t<div id=\"daexthefup-container\"\r\n\t\t\t\tclass=\"daexthefup-container daexthefup-layout-stacked daexthefup-alignment-center\"\r\n\t\t\t\tdata-post-id=\"20504\">\r\n\r\n\t\t\t\t<div class=\"daexthefup-feedback\">\r\n\t\t\t\t\t<div class=\"daexthefup-text\">\r\n\t\t\t\t\t\t<h3 class=\"daexthefup-title\">Was this helpful?<\/h3>\r\n\t\t\t\t\t<\/div>\r\n\t\t\t\t\t<div class=\"daexthefup-buttons-container\">\r\n\t\t\t\t\t\t<div class=\"daexthefup-buttons\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t<div class=\"daexthefup-yes daexthefup-button daexthefup-button-type-icon\" data-value=\"1\">\r\n\t\t\t\t\r\n                <svg>\r\n                    <defs>\r\n                        <style>.thumb-up-cls-1{fill:#c9c9c9;}.thumb-up-cls-2{fill:#e1e1e1;}.thumb-up-cls-3{fill:#676767;}<\/style>\r\n                    <\/defs>\r\n                    <g id=\"thumb_up\">\r\n                        <path class=\"thumb-up-cls-2 daexthefup-icon-circle\" d=\"m24,3c11.58,0,21,9.42,21,21s-9.42,21-21,21S3,35.58,3,24,12.42,3,24,3m0-1C11.85,2,2,11.85,2,24s9.85,22,22,22,22-9.85,22-22S36.15,2,24,2h0Z\" \/>\r\n                        <g>\r\n                            <rect class=\"thumb-up-cls-3 daexthefup-icon-secondary-color\" x=\"10\" y=\"20\" width=\"6\" height=\"15\" rx=\"1.5\" ry=\"1.5\" \/>\r\n                            <path class=\"thumb-up-cls-1 daexthefup-icon-primary-color\" d=\"m30.57,9.06l-.49-.1c-.81-.17-1.61.35-1.78,1.16l-5.3,11.74c-.17.81,3.16,1.61,3.97,1.78l1.96.41c.81.17,1.61-.35,1.78-1.16l2.18-10.27c.34-1.61-.7-3.21-2.31-3.56Z\" \/>\r\n                            <path class=\"thumb-up-cls-1 daexthefup-icon-primary-color\" d=\"m38.17,20h-18.67c-.83,0-1.5.67-1.5,1.5v12c0,.83.67,1.5,1.5,1.5h16.27c.71,0,1.33-.5,1.47-1.21l2.4-12c.19-.93-.53-1.8-1.47-1.8Z\" \/>\r\n                        <\/g>\r\n                    <\/g>\r\n                <\/svg>\t\t\t<\/div>\r\n\r\n\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t<div class=\"daexthefup-no daexthefup-button daexthefup-button-type-icon\" data-value=\"0\">\r\n\t\t\t\t\r\n                <svg>\r\n                    <defs>\r\n                        <style>.thumb-down-cls-1{fill:#c9c9c9;}.thumb-down-cls-2{fill:#e1e1e1;}.thumb-down-cls-3{fill:#676767;}<\/style>\r\n                    <\/defs>\r\n                    <g id=\"thumb_down\">\r\n                        <path class=\"thumb-down-cls-2 daexthefup-icon-circle\" d=\"m24,3c11.58,0,21,9.42,21,21s-9.42,21-21,21S3,35.58,3,24,12.42,3,24,3m0-1C11.85,2,2,11.85,2,24s9.85,22,22,22,22-9.85,22-22S36.15,2,24,2h0Z\" \/>\r\n                        <g>\r\n                            <rect class=\"thumb-down-cls-3 daexthefup-icon-secondary-color\" x=\"10\" y=\"13\" width=\"6\" height=\"15\" rx=\"1.5\" ry=\"1.5\" \/>\r\n                            <path class=\"thumb-down-cls-1 daexthefup-icon-primary-color\" d=\"m30.57,38.94l-.49.1c-.81.17-1.61-.35-1.78-1.16l-5.3-11.74c-.17-.81,3.16-1.61,3.97-1.78l1.96-.41c.81-.17,1.61.35,1.78,1.16l2.18,10.27c.34,1.61-.7,3.21-2.31,3.56Z\" \/>\r\n                            <path class=\"thumb-down-cls-1 daexthefup-icon-primary-color\" d=\"m38.17,28h-18.67c-.83,0-1.5-.67-1.5-1.5v-12c0-.83.67-1.5,1.5-1.5h16.27c.71,0,1.33.5,1.47,1.21l2.4,12c.19.93-.53,1.8-1.47,1.8Z\" \/>\r\n                        <\/g>\r\n                    <\/g>\r\n                <\/svg>\t\t\t<\/div>\r\n\r\n\t\t\t\t\t\t\t\t\t<\/div>\r\n\t\t\t\t\t<\/div>\r\n\t\t\t\t<\/div>\r\n\r\n\t\t\t\t<div class=\"daexthefup-comment\">\r\n\t\t\t\t\t<div class=\"daexthefup-comment-top-container\">\r\n\t\t\t\t\t\t<label id=\"daexthefup-comment-label\" class=\"daexthefup-comment-label\"><\/label>\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"daexthefup-comment-character-counter-container\">\r\n\t\t\t\t\t\t\t\t<div id=\"daexthefup-comment-character-counter-number\"\r\n\t\t\t\t\t\t\t\t\tclass=\"daexthefup-comment-character-counter-number\"><\/div>\r\n\t\t\t\t\t\t\t\t<div class=\"daexthefup-comment-character-counter-text\"><\/div>\r\n\t\t\t\t\t\t\t<\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t<\/div>\r\n\t\t\t\t\t<textarea id=\"daexthefup-comment-textarea\" class=\"daexthefup-comment-textarea\"\r\n\t\t\t\t\t\t\t\tplaceholder=\"Type your message\"\r\n\t\t\t\t\t\t\t\tmaxlength=\"\r\n\t\t\t\t\t\t\t\t400\t\t\t\t\t\t\t\t\t\"><\/textarea>\r\n\t\t\t\t\t<div class=\"daexthefup-comment-buttons-container\">\r\n\t\t\t\t\t\t<button class=\"daexthefup-comment-submit daexthefup-button\">Submit<\/button>\r\n\t\t\t\t\t\t<button class=\"daexthefup-comment-cancel daexthefup-button\">Cancel<\/button>\r\n\t\t\t\t\t<\/div>\r\n\t\t\t\t<\/div>\r\n\r\n\t\t\t\t<div class=\"daexthefup-successful-submission-text\">Thanks for your feedback!<\/div>\r\n\r\n\t\t\t<\/div>\r\n\r\n\t\t\t","protected":false},"excerpt":{"rendered":"<p>Introduction to Microsoft VBScript (Visual Basic Script):\u00a0VBScript Tutorial #1 In today&#8217;s scenario, VBScript has turned out to be a very important topic, especially for beginners who wish to learn the scripting language or automation tools like QTP\/UFT. =&gt;\u00a0Click Here For The QTP Training Tutorials Series =&gt; SCROLL DOWN to see &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"VBScript Tutorial for Beginners\" class=\"read-more button\" href=\"https:\/\/www.softwaretestinghelp.com\/vbscript-tutorial-1\/#more-20504\" aria-label=\"Read more about VBScript Tutorial for Beginners\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":21140,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_helpful_pro_status":1,"footnotes":""},"categories":[406],"tags":[],"class_list":["post-20504","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vbscript"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/posts\/20504","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/comments?post=20504"}],"version-history":[{"count":0,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/posts\/20504\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/media\/21140"}],"wp:attachment":[{"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/media?parent=20504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/categories?post=20504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/tags?post=20504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}