Sunday, March 29, 2020

VBScript tutorial 6 | While Wend | Do While Loop | Working with Excel

Moving on to the next tutorial in the VBScript Tutorials for Beginners. This VBScript beginner tutorial explains the VBScript While Wend loop and the VBScript Do While loop. It also gives the VBScript code to create an Excel file. Please view the VBScript tutorial 6 or read on... A While Wend statement in VBScript is a conditional statement. It is useful when we don't know the number of times a code block should run. The While Wend loop runs a code block while a condition is true. Let us see VBScript While Wend example.

' VBScript code
Option Explicit
Dim i
' Initialize the counter variable, i
i = 1
Loop1

Sub Loop1
While i<= 5
    MsgBox "The current value of i is " & i, vbInformation, "While loop"
    ' Increment the value of i
    i = i + 1
Wend
End Sub

A Do While statement in VBScript is also a conditional statement. Like the While Wend statement, it is useful when we don't know the number of times a code block should run. The VBScript Do loop has two variations. The first variation of the VBScript Do While Loop checks if a condition is true. If the condition is true, it runs a code block. A VBScript Do While Loop statement example is in the Sub Loop1 below. The second variation of the VBScript Do Loop While runs a code block, and then checks if a condition is true. A VBScript Do Loop While statement example is in the Sub Loop2 below. Even if the condition is false, the Do Loop While statement runs the code block once (because it checks the condition after running the code block).

' VBScript code
Option Explicit
Dim i
Loop1
Loop2

Sub Loop1
i = 1
Do While i<=5
    MsgBox "The current value of i is " & i, vbInformation, "Do While Loop"
    i = i + 1
Loop
End Sub

Sub Loop2
i = 1
Do
    MsgBox "The current value of i is " & i, vbInformation, "Do Loop While"
    i = i + 1
Loop While i <= 5
End Sub

Next, let us see the VBScript code to create an Excel file. This VBScript uses the VBScript With statement that allows us to specify an object. The benefit is that we don't have to repeat that object's name on every line of code between the With statement and the End With statement.

Sunday, March 22, 2020

VBScript tutorial 5 | For Next Statement

This is the next tutorial in the VBScript Tutorials for Beginners. This VBScript beginner tutorial explains a VBScript conditional statement, the VBScript For Next statement, which is a loop statement in VBScript. Please view the VBScript tutorial 5 or read on... What is loop in VBScript? A loop is a code block that can run repeatedly, depending on a condition. For Next loop in VBScript runs a fixed number of times. Let us see VBScript for loop examples.

'VBScript code
Option Explicit
Dim i
Call Loop1
Call Loop2
Call Loop3

Sub Loop1
For i = 1 to 5
    ' All statement(s) between For and Next statements are run for each value of i from 1 to 5.
    MsgBox "The current value of i is " & i, vbInformation, "For Loop1"
Next
End Sub

Sub Loop2
For i = 1 to 10 Step 2
    ' The statement(s) are run for the values of i from 1 to 10, increasing by 2 every time.
    MsgBox "The current value of i is " & i, vbInformation, "For Loop2"
    ' Uncomment the following If Then statement to exit the For loop when i is 5.
    'If i = 5 Then Exit For
Next
End Sub

Sub Loop3
For i = 10 to 1 Step -2
    ' The value of decreases from 10 to 1, by 2 every time.
    MsgBox "The current value of i is " & i, vbInformation, "For Loop3"
Next
End Sub

Next, let us learn about the For Each loop in VBScript. It runs a code block on each value in an array or a collection. Let us see a VBScript for each loop example. This VBScript code lists the files present in the given folder.

Sunday, March 15, 2020

Wed, Mar 18 | Augmenting Automated Tests | Live Webinar Invitation

Here is a webinar, Augmenting Automated Tests using Testim Actions. This webinar would be useful for beginners in test automation or automated testing. The presentation would show us how to take our recorded test and augment it with configurable actions, to convert it to a fully functional automated test case. 

Wednesday, March 18th (1-hour duration)
9 am PST/ 12 pm EST/ 4 pm UTC/ 9:30 pm IST
Note: If you register but cannot attend the live webinar due to any reason, you will be still able to see it's recording later.

Let me know if you have any questions. Thank you.



Tuesday, March 10, 2020

VBScript tutorial 4 | Select Case Statement

This is the fourth tutorial in the VBScript Tutorials for Beginners. This VBScript beginner tutorial explains VBScript conditional statement, the Select Case statement. Please view the short VBScript tutorial 4 or read on... The VBScript Select Case statement evaluates an expression. The Select Case statement is followed by Case code blocks. Depending on the value of the expression, exactly one case block is run. If the expression value is not given in any Case above, the Case Else code block is run. The example of a VBScript Select Case statement is as follows:

' VBScript code
Option Explicit
Call Main

Sub Main
    Dim stringA, stringB
    'the first string would be the first argument of the VBScript run from command line
    stringA = Wscript.Arguments.Item(0)
    ' the second string would be the second argument of the VBScript
    stringB = Wscript.Arguments.Item(1)
   ' compare strings in VBScript
    Select Case StrComp(stringA, stringB)
        'StrComp function returns 0 is both the strings are equal
        Case 0
            'MsgBox has three arguments (the message, the icon and the title)
            MsgBox "Both the strings are the same.", vbInformation, "Success"
        'StrComp function returns 1 if the first string is greater
        Case 1
            MsgBox stringA &" is greater than " & stringB, vbQuestion, "Warning"
        'StrComp function returns -1 if the first string is smaller
        Case -1
            MsgBox stringA & " is less than " & stringB, vbQuestion, "Warning"
        Case Else
            MsgBox "There is an error in string comparison.", vbCritical, "Error"
    End Select
End Sub

Since this script needs two arguments to run, we cannot just double-click this VBscript. That would give a subscript out of range error. Instead, we can open the command window (cmd command). Then, change directory (cd command) to the folder that has our script. Give the commands as the script name followed by arguments like the examples below:
  • StringCompare.vbs xyz xyz
  •  StringCompare.vbs abc a
  • StringCompare.vbs d def
Want to understand the VBScript Select Case statement and string comparison in VBScript better? Please view my VBScript tutorial 4. Thank you.

Sunday, March 1, 2020

Tue, Mar 10 | ROI Test Automation | Live Webinar Invitation

Here is a session titled, Justifying and Realizing a Strong ROI (meaning Return On Investment) on Test Automation. This webinar would be useful for present or future Test Leads, QA Leads and QA Managers. This webinar would prepare us to make an appealing case for test automation (or any software investment) to our management. You may register for this webinar here.

The presentation would be made by Testim's Director of Product Marketing, Shawn Jacques. Just because you have budget allocated for a tool does not mean that it will be approved. How do you prove time or cost savings? In the case of test automation tools, how do you measure the benefits of higher quality? This presentation would cover various financial models and how to apply them, linking your test automation investment to your company's strategic initiatives, costs and benefits of test automation and the key metrics that should be measured.

Register today (only limited seats) at http://bit.ly/2v8a8k2
Tue, Mar 10, 2020 (1-hour duration)
9 am PST/ 12 pm EST/ 5 pm UTC/ 10:30 pm IST
Note: If you register but cannot attend the live event due to any reason, you will be still able to see it's recording later.

Let me know if you have any questions. Thank you.