![]() |
| |||||||
Automation Anywhere Post messages and questions related to Automation Software here. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| |||
|
I'm trying to create a multiple IF statement with a Variable, but can't figure out the correct syntax. I have a variable that I've called $Random$ that is configured as follows: Random Type: List Option: Values Values: A;B;C;D I want the following achieved: If $Random$ Includes 'A' Then Mouse Click: Position 1 Includes 'B' Then Mouse Click: Position 2 Includes 'C' Then Mouse Click: Position 3 Includes 'D' Then Mouse Click: Position 4 At present I have it setup as follows: If $Random$ Includes 'A' Then Mouse Click: Position 1 End If If $Random$ Includes 'B' Then Mouse Click: Position 2 End If If $Random$ Includes 'C' Then Mouse Click: Position 3 End If If $Random$ Includes 'D' Then Mouse Click: Position 4 End If I assume this is wrong as this will randomly generate A,B,C,D four times, but I can't figure out how to assess multiple IF's against a variable that is generated once. Can anyone help. Thanks. Dunc |
| |||
|
Hello desm35, We recommend you to replace the operator from "includes" to "equals". For example: The following If statement: If $Random$ Includes 'A' Then Mouse Click: Position 1 End If If $Random$ Includes 'B' Then Mouse Click: Position 2 End If If $Random$ Includes 'C' Then Mouse Click: Position 3 End If If $Random$ Includes 'D' Then Mouse Click: Position 4 End If Has to be changed to: If $Random$ Equals 'A' Then Mouse Click: Position 1 End If If $Random$ Equals 'B' Then Mouse Click: Position 2 End If If $Random$ Equals 'C' Then Mouse Click: Position 3 End If If $Random$ Equals 'D' Then Mouse Click: Position 4 End If Please let us know how it goes for you. Thanks & Regards |
| |||
|
Ok, I've changed 'Includes' to 'Equals' which in my situation does actually do the same thing. What I am actually after is the correct syntax to randomly generate either A,B,C,D only once. Depending on which letter is generated, the mouse would then click in the spot designated to that letter. Here's the process: 1) Randomly generate either A,B,C or D. 2a) IF, random generation = 'A', Then Mouse Click in Position 1 2b) IF, random generation = 'B', Then Mouse Click in Position 2 2c) IF, random generation = 'C', Then Mouse Click in Position 3 2d) IF, random generation = 'D', Then Mouse Click in Position 4 A,B,C or D should only be randomly generated once and then the appropriate mouse click made. At present, I think that my code is randomly generating A,B,C,D four times, which is incorrect. Thanks. Dunc |
| |||
|
Hello desm35, Instead of creating a new variable, you can make use of "my-list variable" which works similar to the array of values. You can read the values randomly by having the "make random" check box active while editing the "my-list variable" and inserting the list of values you want to use in your task. Then you can make use of the "if-else-is" conditional construct according to your requirement. Please find a task attached with this post according to your requirement. Instead of the mouse clicks, we have used "message box". Thanks & Regards |
| |||
|
I've attached an updated version of your test. I am still finding that with your latest suggestion, the code creates multiple mouse clicks in one loop of the process. In one loop of my code it often clicks more than once. For example, in one loop it may click in Position 1 twice and Position 2 once. On another loop it may click in Position 1 once, Position 2 once and Position 3 once. It is as if the random letter is being generated more than once giving the possibility that, say 'A', 'B' and 'D' for example may be generated and thus mouse clicks would be made in Position 1,2 and 4. I want only one letter to be generated on the entire loop of the process. On this 1st loop a 'B' may be generated for example and the mouse would click in Position 2. On the 2nd loop (it is set to 10 loops) a 'D' may be generated and thus a mouse would be made in Position 4. Any ideas. Dunc |
| |||
|
keep us posted on how this works for you. You might consider instead, using an XCEL spreadsheet with the random function and read the mouse positions and click on them. The IF constructs withing AA are minimal. Use AA for those things at which it excels. Use excel calculate the random values. Use AA to click where you need it. good luck. Phil |
| |||
|
Are you sure that AA can't do what I am after? It seems like quite a sophisticated program being able to create quite complex variables. You say that the IF constructs are quite minimal, but there are options for IF, IF ELSE and ELSE. Surely this is enough to construct code that: 1) Generates a random letter. 2a) IF the random letter = 'A', then click in Position 1 2b) IF the random letter = 'B', then click in Position 2 2c) IF the random letter = 'C', then click in Position 3 2d) IF the random letter = 'A', then click in Position 4 Surely the code I have attached to this thread just needs tweaking - the syntax is just slightly wrong? Dunc |
| |||
| Quote:
IF A or B? IF A or B and C? thats what I mean by minimal. the problem you have MAY be related to the creation of the $RANDOM$ variable. I saw you were working with a LIST. ? why ? If $RANDOM$ < 2 then variable operation $X$ = 200 variable operation $Y$ = 400 Else if $RANODOM$ < 3 then variable operation $X$ = 300 variable operation $Y$ = 500 etc... end if end if mouse click $X$ $Y$ Last edited by philkryder; 09-16-2011 at 10:12 AM. |
| |||
|
There are many ways to solve this. This is more a question of structuring If statements and loops in programming rather then specific to AA. 1 - If $Random$ Includes 'A' Then Mouse Click: Position 1 Else If If $Random$ Includes 'B' Then Mouse Click: Position 2 Else If If $Random$ Includes 'C' Then Mouse Click: Position 3 Else If If $Random$ Includes 'D' Then Mouse Click: Position 4 End If 2 - You can put it in a loop which will exit as soon as the new page loads (assuming that`s what the mouse click is intended to do). |
![]() |
| Thread Tools | |
| Display Modes | |
| |