Hi, I am trying to add two UI elements that I have extracted from a webpage using the Get Text activity. Now I want to add these two values and enter them in an input box on the same webpage. But the problem is that the extracted value is in String format so instead of adding it appends.
In the above image as you can see there are two elements 8 and 2. I want to add this and enter the result in the input box. Right now the result is 82.
Hi @Vignesh_Satheesh1
You need to Convert both to Result variable and Then Use + Symbol
Cint(getTextVar1)+Cint(getTextVar2)
Regards
Hi, @pravin_calvin thank you for your reply. I am using the save value for later option to store the result from getting text activity. How do I convert it after? I am using type into activity to enter the result in the input box.
@Vignesh_Satheesh1
Use the above expression that I have mentioned in type into activity,!
Regards
I believe you are using STUDIOX
So save the get text activity output as save for later and name it as value1
And another as value2
In that case with TYPE INTO activity click on the plus symbol and choose TEXT as option
There type as
Convert.ToInt32()
And now keep the cursor between curly braces and click on + symbol and click on USE SAVED VALUE and choose value1 and it will now look like this
Convert.ToInt32(value1)
Now continue typing as
Convert.ToInt32(value1) + Convert.ToInt32()
Again between the braces keep the cursor and click on plus symbol and choose use saved value and select value2
It will finally look like this
Convert.ToInt32(value1) + Convert.ToInt32(value2)
That’s it it will work like adding two numbers
Cheers @Vignesh_Satheesh1
1 Like
Hi @Palaniyappan, I tried this way but this isn’t working. This is storing value in the input box like that Convert.ToInt32(Var1) + Convert.ToInt32(Var2). I can see the dynamic number instead of Var 1 and 2
This was the formula that was used. I just copied it
Convert.ToInt32(<[Saved.Values(Of UiPath.Excel.ExcelValue)(“Var1”)]>) + Convert.ToInt32(<[Saved.Values(Of UiPath.Excel.ExcelValue)(“Var2”)]>)
Break it down into smaller steps…
Your captured values are text. You can’t make numeric calculations with text, it’ll lead to concatenations as you experienced, instead of additions.
It’s one of the fundamentals on data types.
Text “5” is different from a number/integer 5
Similar, data you enter in controls are text, they are visible characters. So after a calculation you need to convert again.
So:
- read the text
- convert text to numbers
- do the calculation
- convert back to text
- update the UI with a value.
It can be done with almost a single expression, but the fundamental understanding of this makes writing the expression a whole lot easier, by first breaking it down (at least in your head).
So:
Read the text:
get text activity --> results a string 'strValue1'
get text activity --> results a string 'strValue2'
Convert to numbers:
intValue1 = cInt(strValue1)
intValue2 = cInt(strValue2)
Calculation:
intResult = intValue1 + intValue2
Convert back to text
strResult = intResult.ToString
Add text to UI:
Set Text / Type into: strResult
And indeed you can shorthand steps 2-4 into this:
Type into: (cInt(strValue1) + cInt(strValue2)).toString