Skip to content

Iptv Assist

Learn More from us

Menu
  • HOW TO
  • Firestick
  • Chromecast
  • PC Apps
  • Lg Smart TV
  • IPTV Services
  • Automation Testing
  • Smart TV
  • Software Testing Tools
  • Contact Us
Menu

QTP Tutorial #10 – Writing Loop and Conditional Statements – VB Script Basics Part 2

Posted on January 22, 2023

Best Iptv Service Provider 2023 With 40k+ Channels And 100k+ VOD . 24/7 Suppport . Paypal Supported

VB Scripting Basics – Writing Loop and Conditional Statements for Building the Programming Logic.

Best Iptv Service Provider 2023 With 40k+ Channels And 150k+ VOD . Hurry Up

=> Click Here For The QTP Training Tutorials Series

Recommended IPTV Service Providers

  1. IPTVGREAT – Rating 4.8/5 ( 600+ Reviews )
  2. IPTVRESALE – Rating 5/5 ( 200+ Reviews )
  3. IPTVGANG – Rating 4.7/5 ( 1200+ Reviews )
  4. IPTVUNLOCK – Rating 5/5 ( 65 Reviews )
  5. IPTVFOLLOW -Rating 5/5 ( 48 Reviews )
  6. IPTVTOPS – Rating 5/5 ( 43 Reviews )

 

=> Also read the complete free VBScripting Tutorial series here

In the last VB Scripting article, we saw some of the basic features of the VB script. Here, we are going to learn a few more programming concepts before we conclude our introduction series.

Writing Loop and Conditional Statements

What You Will Learn:

  • Conditional Statements
  • Looping Statements
  • Best Practices for Code Writing in VB Script
  • Conclusion

Conditional Statements

#1) If Statement

If (condition)..Then
{Statement or a block of statement}
Else
{Statement or a block of statement}
End if

VB Script tutorials

This is the typical syntax to write this statement.

  • The if..then..else statements can be nested to any number of levels.
  • Alternately, the else block can be used or not.
  • Elseif is another variation that can be used while choosing one of the multiple options.

if x=0 then
Msgbox “value=0”
Elseif x=1 then msgbox “value=1”
Elseif x=2 then msgbox “value=2”
Else msgbox “value not found”
End if

#2) Select Statement

This is to choose one out of the many options depending on the condition that comes satisfied. The condition is evaluated once and based on the value it attains, one of the following blocks of code gets chosen to be run.

Select Case (expression)
Case “case1”
{Block 1}
Case “case 2”
{Block 2}
…..
Case Else
{Else block}
End Select

Looping Statements

There are 4 kinds of loop statements:

#1) Do…loop

This is used when a statement or a block of statements needs to be executed while or until a said condition is true.

Let us first  look at the syntax of this:

Syntax 1:
Do (While | Until) condition
{Statement or statements}
[Exit Do]
{Statement or statements}
Loop

Syntax 2:
Do
{statement or statements]
[Exit Do]
{statement or statements]
Loop [{While | Until} condition]

Condition: Could be a numeric or string component that either attains a true or false value. If the condition is null it is treated as False.
Observe the ‘Exit do’ in the above.

There is also a slight difference between syntax 1 and syntax 2.

In the case of syntax 1, the statements within the do loop do not get executed unless the condition becomes true or holds true.

For syntax 2, the statements within the loop get executed at least once, and then the check is performed on the condition.

Exit Do: In order to avoid infinite loops we will have to force the loop to exit. Exit Do is a statement that is used in such circumstances.

#2) While…wend

Syntax:

While
{Statement or block of statement}
Wend

It is self-explanatory from the syntax that the statements nestled under the while block get executed as long as the condition holds true.

Although this statement is available, it is not very flexible, hence it is recommended to use the Do…Loop statement.

#3) For…Next

This is the statement that you would use when you want a statement/set of statements to run a certain number of times while a certain counter gets incremented or decremented.

For counter = start To end [Step step]
[statements]
[Exit For]
[statements]
Next

  • As you can see from the syntax above, there is a “Step” clause to this statement. This clause is optional.
  • The step clause if not specified, the for loop steps one counter forward by default.
  • The step can be used to increment or decrement the counter value.
  • Exit For is similar to “Exit Do” which can be used to come out of the For block and execute the statement that follows.
  • Any number of Exit For statements can be used within one block of For statement.
  • It is usually used with an if..then statement to make sure some condition that would lead to infinitely looping is true and in case if it does, the For statement has a way to exit.
  • Any number of For statements can be nested within a For.

Example:

For i=1 to 10
……
If x=true then
……
Exit for
End if
Next

Example of a positive step:
For i = 2 To 12 Step 2
total = total + k
Next

Example of a negative step:
For i = 12 To 2 Step -2
total = total + k
Next

#4) For each…next

This is similar to ‘For …next’. It is used for collection objects or arrays. This statement runs a statement or a set of statements for every object or item in an array instead of the number of times specified.

As the ‘For…next’ statement Exit is used to exit before the looping is through, like in case of an error. Also, any number of For each statement can be nested within each other.

Syntax:

For Each element In group
[statements]
[Exit For]
[statements]
Next [element]

  • The element is the variable that is used to iterate through the elements in the array or collection object.
  • The group stands for the name of the collection object or array.

Note:  We have not discussed collection objects so far in our series, but a collection object is nothing but an object which is a set of related items (objects, these might be of the same type or could be of different types)

Best Practices for Code Writing in VB Script

  • At the beginning of every program, write down a brief description of what the program does.
  • Provide comments for each variable used during its declaration to briefly describe what this variable is going to do.
  • Keep the code as modular as possible.
  • Have the main program readable and have all the logic segregated in terms of function, so that it makes them easy to read and maintain.
  • The segregation of code into functions will also increase reusability.
  • An agreed naming convention has to be used to maintain consistency.
  • Comments – Provide comments to make the code more understandable.
  • Indentation – Make sure that you indent the lines of code to clearly understand the sequence of execution.
  • Option Explicit is to be declared so that you don’t run into an issue when you have a spelling mistake in a variable name.
  • Watch out for infinite loops.

Conclusion

This concludes our brief introduction to VB Script. As already mentioned, this is in no way a complete guide to learning the scripting language but is enough to get us through writing beginner to moderate level QTP programs.

There is one function topic that we did not cover here, but that exclusion was deliberate. This is because functions are lengthy and a very important topic which we will discuss in detail in the upcoming articles.

The next article in our QTP training series is going to be about the Expert view and we will try to include some checkpoints too. Feel free to post your questions.

=> Visit Here For The QTP Training Tutorials Series

=> Also read the complete free VBScripting Tutorial series here

Related

Best Iptv Service Provider 2023 With 40k+ Channels And 150k+ VOD . Hurry Up

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • IPTV List: Best iptv lista 2023
  • IPTV Premium: Best Premium IPTV Service Provider List And Benefits
  • Nikon IPTV Review: Over 10,000 Live Channels for $12/Month
  • Iptvwings. Com Review: +18000 Live IPTV Channels ,+70000 Movies, +40000 TV show For $15/1 month
  • IPTVUNO Review: More Than 16000 Live TV channels, 55,000 Movies & VOD For $15/Month

Recent Comments

  1. IPTV List: Play lista iptv 2022 - Iptv Assist on Best IPTV Player in 2023 for Watching Live TV
  2. Cola IPTV – Over 18,000 Live Channels for $12/Month - Iptv Assist on FileLinked – How to Install on Firestick/Fire TV and Android Devices
  3. Cola IPTV – Over 18,000 Live Channels for $12/Month - Iptv Assist on 50+ Best IPTV Service Providers for Streaming Live TV 2023
  4. XoomsTV IPTV – Over 11,000 Channels & VOD for Under $13/Month on Best VPN for IPTV in 2023 and How to Install on Firestick/Android
  5. Voodoo Streams IPTV Review – Over 12,000 Channels for $11/Month - Iptv Assist on Dynasty TV IPTV Review – Over 6,000 Channels for $10/Month

Archives

  • January 2023

Categories

  • Activate
  • Agile Testing
  • Alternatives
  • Android
  • APK
  • Apple TV
  • Automation Testing
  • Basics of Software Testing
  • Best Apps
  • Breakfast Hours
  • Bug Defect tracking
  • Career in Software Testing
  • Chromebook
  • Chromecast
  • Cross Platform
  • Database Testing
  • Delete Account
  • Discord
  • Error Code
  • Firestick
  • Gaming
  • General
  • Google TV
  • Hisense Smart TV
  • HOW TO
  • Interview Questions
  • iPhone
  • IPTV
  • IPTV Apps
  • Iptv Service SP
  • IPTV Services
  • JVC Smart TV
  • Kodi
  • Lg Smart TV
  • Manual Testing
  • MI TV
  • Mobile Testing
  • Mod APK
  • newestiptv.com
  • News
  • Nintendo Switch
  • Panasonic Smart TV
  • PC Apps
  • Performance Testing
  • Philips Smart TV
  • PS4
  • PS5
  • Python
  • QA Certifications
  • QA Leadership
  • QA Team Skills
  • Quality Assurance
  • Reddit
  • Reviews
  • Roku
  • Samsung Smart TV
  • Screenshot
  • Selenium Tutorials
  • Sharp Smart TV
  • Skyworth Smart TV
  • Smart TV
  • Soft Skills For Testers
  • Software Testing Templates
  • Software Testing Tools
  • Software Testing Training
  • Sony Smart TV
  • Sports
  • Streaming Apps
  • Streaming Devices
  • Tech News
  • Test Management Tools
  • Test Strategy
  • Testing Best Practices
  • Testing Concepts
  • Testing Methodologies
  • Testing News
  • Testing Skill Improvement
  • Testing Tips and Resources
  • Toshiba Smart TV
  • Tutorials
  • Twitch
  • Types of Testing
  • Uncategorized
  • Vizio Smart TV
  • VPN
  • Web Testing
  • What is
  • Xbox
©2023 Iptv Assist | Design: Newspaperly WordPress Theme