{"id":1153,"date":"2012-02-09T02:17:23","date_gmt":"2012-02-08T20:47:23","guid":{"rendered":"http:\/\/www.automationrepository.com\/?p=1153"},"modified":"2012-02-09T02:17:53","modified_gmt":"2012-02-08T20:47:53","slug":"part-3-qtp-and-vbscript-writing-the-first-vbscript-program","status":"publish","type":"post","link":"https:\/\/www.automationrepository.com\/wordpress\/2012\/02\/part-3-qtp-and-vbscript-writing-the-first-vbscript-program\/","title":{"rendered":"Part 3: QTP and VBScript | Writing your first program in VBScript"},"content":{"rendered":"<div style=\"text-align: justify; font-family: Verdana;\">\n<p>Before starting with the code intensive topics (such as working with conditional statements &amp; loop constructs in VBScript) as part of the <a title=\"QTP Tutorials\" href=\"http:\/\/www.automationrepository.com\/tutorials-for-qtp-beginners\/\">QTP Tutorials<\/a> series, it would be a good idea to first touch upon the most basic stuff in VBScript, which is <strong>&#8216;Writing and executing your first program in VBScript&#8217;<\/strong>. <em>This is important because<!--more--> once you are clear with this concept, you can write your own scripts and thus practice the different concepts that will be covered in the remaining articles of <a title=\"QTP VBScript Tutorials\" href=\"http:\/\/www.automationrepository.com\/category\/qtp-and-vbscript-tutorials\/\" target=\"_blank\">QTP VBScript Tutorials<\/a> series.<\/em><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" title=\"Writing first VBScript Program\" src=\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/running-vbscript-code.png\" alt=\"Writing first VBScript Program\" width=\"373\" height=\"135\" \/><\/p>\n<p><em> <\/em><br \/>\n<strong>Although you can use QTP to run VBScript code snippets, its not an absolute requirement that you have QTP installed in your system. This is because VBScript comes installed by default in all Windows machines since Windows 98. So all you need is a text editor (like notepad) to write &amp; execute VBScript code.<\/strong><br \/>\n<em> <\/em><br \/>\nLets see how you can create and execute VBScript programs directly using a text editor and by using QTP. In this article, we would execute a very basic VBScript program which displays some text in a message box.<br \/>\n<span><br \/>\n<\/span><\/p>\n<h3>Executing VBScript code without QTP<\/h3>\n<p>You can follow the below mentioned steps to run a VBScript program without using QTP.<br \/>\n<strong>1)<\/strong> Open any text editor (We&#8217;ll be using Notepad for this example).<br \/>\n<strong>2)<\/strong> Write the following code in notepad window.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n'Declare a variable\r\nDim sMessage\r\n\r\n'Assign a value to the variable\r\nsMessage = &quot;This script is executed without using QTP&quot;\r\n\r\n'Display the text in a messagebox\r\nMsgbox sMessage\r\n<\/pre>\n<p><strong>3)<\/strong> <strong>Save the file with a .vbs extension<\/strong> (like Demo1.vbs).<br \/>\n<span style=\"text-decoration: underline;\">Make sure that the file is saved as SomeName.vbs only and not SomeName.vbs.txt. To verify this, open any folder and go to &#8216;Tools -&gt; Folder Options&#8217;, then select View tab and uncheck &#8216;Hide extensions for known file types&#8217; check box. Then verify that the file doesn&#8217;t contain .txt extension at the end.<\/span><\/p>\n<p><strong>4)<\/strong> After the file is saved, double-click on the file icon. This would display a message box as shown in the below figure.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" title=\"Running VBScript code without QTP\" src=\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/run-vbscript-code-1.png\" alt=\"Running VBScript code without QTP\" width=\"419\" height=\"178\" \/><br \/>\n<span><br \/>\n<\/span><\/p>\n<h3>Executing VBScript code using QTP<\/h3>\n<p>In addition to using the above mentioned steps to write your scripts in notepad, you can also write and execute your VBScript code through QTP. To do so &#8211;<br \/>\n<strong>1)<\/strong> Open a new test in QTP.<br \/>\n<strong>2)<\/strong> Copy the following code in QTP test.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n'Declare a variable\r\nDim sMessage\r\n\r\n'Assign a value to the variable\r\nsMessage = &quot;This script is written and executed using QTP&quot;\r\n\r\n'Display the text in a messagebox\r\nMsgbox sMessage\r\n<\/pre>\n<p><strong>3)<\/strong> Save the test (if needed).<br \/>\n<strong>4)<\/strong> Run the code using QTP.<br \/>\n<em>Once you run the code in QTP, you would see a message box as shown in the below figure.<\/em><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" title=\"Executing VBScript code using QTP\" src=\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/run-vbscript-code-2.png\" alt=\"Executing VBScript code using QTP\" width=\"284\" height=\"154\" \/><\/p>\n<p><em> <\/em><br \/>\nThis was all about running sample VBScript code snippets in your system &#8211; with and without using QTP. You can use the same approach to write much more complex scripts on your own. Before finishing this article, I have a query for you.. Can you think of any advantages\/disadvantages of using notepad and QTP for writing &amp; executing your VBScript code? Do let us know you thoughts on this using the comments section.<br \/>\n<span><br \/>\n<\/span><\/p>\n<\/div>\n<div style=\"font-family: Verdana,sans-serif; border: 1px solid #C8B560; padding: 3mm; background: #FFF8C6; text-align: center;\">\n<p><strong>If you enjoyed this article, you can join our blog to get new articles delivered directly in your inbox.<\/strong><\/p>\n<form style=\"text-align: center;\" action=\"http:\/\/feedburner.google.com\/fb\/a\/mailverify\" method=\"post\" onsubmit=\"window.open('http:\/\/feedburner.google.com\/fb\/a\/mailverify?uri=automationrepository\/feeds', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true\" target=\"popupwindow\"><input style=\"width: 160px; height: 20px;\" onfocus=\"if (this.value == 'Enter Your Email Address') {this.value = '';}\" onblur=\"if (this.value == '') {this.value = 'Enter Your Email Address';}\" type=\"text\" value=\"Enter Your Email Address\" \/> <input type=\"hidden\" name=\"uri\" value=\"automationrepository\/feeds\" \/> <input type=\"hidden\" name=\"loc\" value=\"en_US\" \/> <input type=\"submit\" value=\"Join Us\" \/><\/p>\n<p style=\"text-align: justify;\">\n<\/form>\n<\/div>\n<p style=\"border: 1px solid #C38EC7; padding: 3mm; background: #EBDDE2;\">To check out more tutorials, visit our <a title=\"QTP Tutorials\" href=\"http:\/\/www.automationrepository.com\/tutorials-for-qtp-beginners\/\" target=\"_blank\">QTP Tutorials<\/a> page. You can also check the <a title=\"All Articles\" href=\"http:\/\/www.automationrepository.com\/archive\/\" target=\"_blank\">Archives<\/a> page to view the list of all our articles.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Before starting with the code intensive topics (such as working with conditional statements &amp; loop constructs in VBScript) as part of the QTP Tutorials series, it would be a good idea to first touch upon the most basic stuff in VBScript, which is &#8216;Writing and executing your first program in VBScript&#8217;. This is important because<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[64,37],"tags":[70],"class_list":["post-1153","post","type-post","status-publish","format-standard","hentry","category-qtp-and-vbscript-tutorials","category-qtp-tutorials-for-beginners","tag-vbscript"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Writing and Executing VBScript Code Snippets using QTP<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.automationrepository.com\/wordpress\/2012\/02\/part-3-qtp-and-vbscript-writing-the-first-vbscript-program\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Anish Pillai\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/02\/part-3-qtp-and-vbscript-writing-the-first-vbscript-program\/\",\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/02\/part-3-qtp-and-vbscript-writing-the-first-vbscript-program\/\",\"name\":\"Writing and Executing VBScript Code Snippets using QTP\",\"isPartOf\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/02\/part-3-qtp-and-vbscript-writing-the-first-vbscript-program\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/02\/part-3-qtp-and-vbscript-writing-the-first-vbscript-program\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/running-vbscript-code.png\",\"datePublished\":\"2012-02-08T20:47:23+00:00\",\"dateModified\":\"2012-02-08T20:47:53+00:00\",\"author\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/02\/part-3-qtp-and-vbscript-writing-the-first-vbscript-program\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.automationrepository.com\/wordpress\/2012\/02\/part-3-qtp-and-vbscript-writing-the-first-vbscript-program\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/02\/part-3-qtp-and-vbscript-writing-the-first-vbscript-program\/#primaryimage\",\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/running-vbscript-code.png\",\"contentUrl\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/running-vbscript-code.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2012\/02\/part-3-qtp-and-vbscript-writing-the-first-vbscript-program\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.automationrepository.com\/wordpress\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Part 3: QTP and VBScript | Writing your first program in VBScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#website\",\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/\",\"name\":\"XX\",\"description\":\"\\r\\nasas\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.automationrepository.com\/wordpress\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20\",\"name\":\"Anish Pillai\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g\",\"caption\":\"Anish Pillai\"},\"description\":\"Find more about Anish Pillai on Google+\",\"sameAs\":[\"http:\/\/www.automationrepository.com\"],\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/author\/anish\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Writing and Executing VBScript Code Snippets using QTP","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.automationrepository.com\/wordpress\/2012\/02\/part-3-qtp-and-vbscript-writing-the-first-vbscript-program\/","twitter_misc":{"Written by":"Anish Pillai","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/02\/part-3-qtp-and-vbscript-writing-the-first-vbscript-program\/","url":"https:\/\/www.automationrepository.com\/wordpress\/2012\/02\/part-3-qtp-and-vbscript-writing-the-first-vbscript-program\/","name":"Writing and Executing VBScript Code Snippets using QTP","isPartOf":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/02\/part-3-qtp-and-vbscript-writing-the-first-vbscript-program\/#primaryimage"},"image":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/02\/part-3-qtp-and-vbscript-writing-the-first-vbscript-program\/#primaryimage"},"thumbnailUrl":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/running-vbscript-code.png","datePublished":"2012-02-08T20:47:23+00:00","dateModified":"2012-02-08T20:47:53+00:00","author":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20"},"breadcrumb":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/02\/part-3-qtp-and-vbscript-writing-the-first-vbscript-program\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.automationrepository.com\/wordpress\/2012\/02\/part-3-qtp-and-vbscript-writing-the-first-vbscript-program\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/02\/part-3-qtp-and-vbscript-writing-the-first-vbscript-program\/#primaryimage","url":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/running-vbscript-code.png","contentUrl":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/running-vbscript-code.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.automationrepository.com\/wordpress\/2012\/02\/part-3-qtp-and-vbscript-writing-the-first-vbscript-program\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.automationrepository.com\/wordpress\/"},{"@type":"ListItem","position":2,"name":"Part 3: QTP and VBScript | Writing your first program in VBScript"}]},{"@type":"WebSite","@id":"https:\/\/www.automationrepository.com\/wordpress\/#website","url":"https:\/\/www.automationrepository.com\/wordpress\/","name":"XX","description":"\r\nasas","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.automationrepository.com\/wordpress\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20","name":"Anish Pillai","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g","caption":"Anish Pillai"},"description":"Find more about Anish Pillai on Google+","sameAs":["http:\/\/www.automationrepository.com"],"url":"https:\/\/www.automationrepository.com\/wordpress\/author\/anish\/"}]}},"_links":{"self":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts\/1153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1153"}],"version-history":[{"count":17,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts\/1153\/revisions"}],"predecessor-version":[{"id":1174,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts\/1153\/revisions\/1174"}],"wp:attachment":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}