Assistance with IF condition to compare to variables

Purpose is to pull the Accuracy of a result as a % and identify the larger % to know what other data I need to screen scrape.
I was considering using Max formula, but I need to capture different screenshots if it is one or the other. I think the formula I used is easy and simple, but due to technical VB knowledge not working. See screenshot below.


Using An assign activity for webindex
And as value if(accuracy2<accuracy1,“1”,“2”) returns a string

So remove the entire “if” box and only have an assign activity for Accuracy and webindex?

Yes, accuracy2 and 1 are converted to numbers. To retrieve 1 or 2 the if statement is enough

I used the Assign box for Accuracy and Webindex and it is not working per “Step Into”.

I used the formula “if(accuracy2<accuracy1,“1”,“2”)” my Accuracy2 = 100, Accuracy1 = 3, the assign activity is assigning a “1”, where as it should be a “2” (100 is not less than 3).

It is performing the same function for the Accuracy variable… only assigning the “then” result not the “else”.

The only other activity I have is the following screenshot, where I extract the % from 100%. same formula for Accuracy1. I do need the Accuracy as a integer because later I have a decision to make sure the value is > 50.


Can you share your xaml file, I’ll check it then

Comparing string representation of numbers as if they would be numbers gives these kind of results where 2 > 19999 = true, due to alphabetically compared nature of strings.

@jbartosh - your CInt’s are a good step, but store the results in Int32 variables (dont tostring the CInt result) and then compare. You want to compare numbers, not text, so you have to have it as number.

Originally tried Int32 but keep receiving errors. For instance below int32 cannot be used as an expression. But Cint works.


Uploaded. It is in the Try/Catch under Results workflow.

Main.xaml (31.3 KB)

There’s your problem - your accuracy variables should be ints, not strings.
Since they represent numbers, you should as soon as they’re fetched (via get visible text) be converted to numbers and from that point on used as numbers (both from process perspective, but you also need to tell the robot that they are numbers - store them in number type variables (int, double, decimal - depending on specific needs)).

string accuracy1; // fetched from gettext
string accuracy2; // fetched from gettext
string webIndex; // string.empty at this point
Int32 accuracyNumber1 = Convert.ToInt32(Accuracy1.Replace("%",”").Trim); // can use CInt instead of Convert.ToInt32, they work pretty much the same, especially for integer numbers
Int32 accuracyNumber2 = Convert.ToInt32(Accuracy2.Replace("%",”").Trim);
   finalAccuracy = accuracyNumber1;
   webIndex = 1;
   finalAccuracy = accuracyNumber2;
   webIndex = 2;

As you can see once you immediately convert and store your values in variable types that they actually represent, the rest of the code becomes pretty much trivial.

1 Like

The issue I continual receive from this answer is UiPath Studio says either (1) the “Replace” and “Trim” functions are aspects of a String not an Int, or (2) cannot assign from type System.Int32 to type System.String in Assign activity.

Then if I create another assign block after trim/replace to store “100” as Int, either cint or convert.toint32, I get “Option Strict On disallows implicit conversions from Integer to String.”


Check attached example - I’ve trimmed it down to just the sequence that’s discussed.
Note how there’s only 1 conversion for each of the accuracies.
If you need to print/use in typeInto etc. the values, use f.e. finalAccuracy.ToString(). Keeping the value in it’s true type and tostring`ing it when you need to type is much easier in the long run (and safer).

JBartosh_IntStringConversion_Main.xaml (11.6 KB)

Other changes/notable things:
Note that the variables have different scopes - since we’re not interested in the accuracy text, but it’s real value, it’s used only before conversion and scoped to the inner sequence (so that it’s not used by accident somewhere else, but also to free it up from memory). Correct scoping is also easier if you name your scope activities (sequences, flowcharts etc.), so that you don’t have a Sequence>Sequence>Sequence>Sequence>Sequence to choose from when choosing scope of a variable.
Note that all of the variables start are in camelCase (start with lowercase, words within have first letter capitalized). It makes it easier to see that they’re indeed variables (and not Arguments), as well as to read them as a human.
Note that I’ve got rid of the inline IIF(...) assignments - they’re not exactly the easiest to read if you’re not used to them, so unless you already have all the syntaxes figured out, avoid them. Execution times differences will be almost non-measurable and at this stage it will be easier to focus on getting the automation right logically.

Since you’ll need finalAccuracy and webIndex outside of this sequence, remember to change it’s scope so it’s accessible, but you should restrain from changing the scope of the other variables, as after this step you should only be interested in those 2 and not in any of the intermediary values.
If you want to make it even clearer, make this a separate workflow and change finalAccuracy and webIndex to OutArguments (and rename them to suit your naming convention for arguments).