Objective
The objective of this practice problem is for the user to demonstrate an understanding of the loop commands discussed in the previous section by creating an automation that utilizes said commands. The commands covered in the previous section were Loop Number of Times and Do While. In the future, these commands may be implemented into other practice problems.
Scenario
A student at the ABC school was punished for not completing his assignments. As a part of his punishment, the teacher asked him to write a caption of his favorite author and add an image related to that caption 3 times. He was also asked to write the multiplication table for the number 5 up until the number 10. (Example: 5 * 1 = 5, 5 * 2 = 10, 5 * 3 = 15, etc.) The file must then be saved.
Prerequisites
None as of now.
Practice Problem Requirements

The user must create an automation that performs the following tasks:

  • Creates a new Word document.
  • Uses the Loop Number of Times command to add an image of the user’s favorite author to the document 3 times.
  • Adds a quote from the author underneath each image.
  • Uses a Do While command to create a times table for the number 5 up until the number 10 and then appends each line to the Word document.
  • Saves and closes the Word document.

Problem Difficulty: Somewhat Easy
Solution will be provided on the next page with a brief explanation.

Solution
The code for the solution has been provided below.

As a quick summary:

Step 1: A new Word document must be created using the Create Word Application command. All Word instances must be closed to avoid errors.

Step 2: The Loop Number of Times command is used to begin and run a loop for the set number of times mentioned in the Loop Count field. It is necessary to mention the start index. In this practice problem, the loop count is 3.

Step 3: The Append Image command is used to append an image to an application. In this practice problem, an image of the user’s favorite author should be added to the Word document created. Instance name and the path of the image should be mentioned as well. This command is placed within the loop.

Step 4: The Append Text command is used to add text to a document. The font name and font size must be mentioned. The text font and style can be decided by the user. This command is placed within the loop as well.

Step 5: The End Loop command allows to end a loop that was previously started. In this practice problem, the loop that was started with the loop count mentioned, has ended after running the loop 3 times.

Step 6: The Set Variable command allows users to assign a value to a variable. The name of the variable and its value needs to be assigned. In this practice problem, a new variable was created with the name “vLoopNum” and is given the value of 1. This will be used later to create the multiplication table.

Step 7: The Set Variable command allows users to assign a value to a variable. The name of the variable and its value needs to be assigned. In this practice problem, a new variable was created with the name “vResult” and is given the value of 0. This will be used later to store the result of a multiplication. A variable can be created in the Variable Manager.

Step 8: The Do While command is used to start a loop. The condition of the loop must be specified from the dropdown menu and the necessary parameters must be added based on the requirement. In this practice problem, a loop is started and set to the condition “Value Compare”, where vLoopNum is less than or equal to 10.

Step 9: The Set Variable command is used when a variable needs to be modified. The name of the variable and its value needs to be assigned. In this practice problem, the variable vResult is set to the value vLoopNum * 5. This is because vLoopNum will be increasing by 1 every loop. This makes it perfect for creating the multiplication table. Now that vResult contains the correct value, it can be used to append the text into the document in the next step. This command is placed within the loop.

Step 10: The Append Text command is used to add text to a document. In this practice problem, the text “5 x vLoopNum = vResult” is added to the Word document created. The text font and style can be decided by the user. This command is placed within the loop as well.

Step 11: The Set Variable command is used when a variable need to be iterated. The name of the variable and its value needs to be assigned. In this practice problem, the variable vLoopNum needs to be incremented by 1 to show that the loop should keep running until the value is less than or equal to 10

Step 12: The End Loop command allows to end a loop that was previously started.

Step 13: The Save Document As command is used to save the document with a name to the project folder.

Step 14: The Close Word Application command is used to close the application that was previously created. In this practice problem, the application that was created with the instance name “LoopPP” is closed.

Newsletter Bot

Lets stay in touch!

Join our weekly newsletter and follow us on social media.

Contact Sales
Call Our Experts!