hjie30
(Marcus)
January 5, 2023, 3:39am
1
Hi guys, I am trying to store a variable value in an array for later use. First I have a string variable known as Price, then I have an array of PriceList. I want to store the value of the Price in the Pricelist. Then I need to get the lowest value in the PriceList. May I know how can I do this?
Note: The Price needs to be a string value, cause I need it to be a string variable for database insertion. For the PriceList what type should it be? String or Double?
Hi @hjie30
Before adding it to the price list, convert the price string to double and then add it to the price list of type double. Then you can get the maximum of price value.
CDbl(price)
Anil_G
(Anil Gorthi)
January 5, 2023, 4:18am
3
@hjie30
If you want to add multiple values better use list rather than array as array is static…
For list you can use append to collection to add data…
And once everything is added
Listvar.Max(function(x) cdbl(x)) will give you the max value
Cheers
1 Like
Hello @hjie30
Try this
If you need to get the value in int, set price list variable as a Array of integer.
While concat, use cint(Stringvariable)
PriceList.Concat({cint(Price)}).ToArray
Then to Get the lowest value use
PriceList.Min.ToString
to Get the lowest value use
PriceList.Max.ToString
To Join value
String.Join(",",PriceList)
hjie30:
Doube?
If you need to get the value in double, set the price list variable as an Array of Double.
While concat, use cdbl(String variable)
PriceList.Concat({cdbl(Price)}).ToArray
@hjie30
Further to @Anil_G ’s post.
Take a look at this video from Anders Jensen.
hjie30
(Marcus)
January 5, 2023, 5:52am
7
May I know why am I having this error? Is it because my pricelist initially is empty?
Hi @hjie30 ,
You would need to initialise the PriceList
array variable in the below manner first :
PriceList = new Double(){}
Also, Would suggest to use Append
, so you wouldn’t need to add the data as an array if each time a single data is being appended to the list :
PriceList.Append(CDbl(Price)).ToArray
Let us know if you are not able to get the output.
Do you have anything the Pricelist before? @hjie30
If not you need to initialize that variable first
sample.Append(Cdbl("22.35")).ToArray
Regards
Sudharsan
hjie30
(Marcus)
January 5, 2023, 6:17am
10
I am not able to use append here, is it because it is an array of double type? How to I change from array type to list type? I never use list before in UiPath
@hjie30
Try removing the double curly braces {} and try again?
Regards
Sudharsan
hjie30
(Marcus)
January 5, 2023, 6:33am
12
This is what happened after removing the curly braces
Actually, it works well using the Concat instead of Append, actually what’s the difference between this two?
Not there @hjie30
In the below expression
Append({Cdbl}) from here remove {}
@hjie30
Kindly Refer to this Xaml file, You may get some idea
Array_Append.xaml (7.7 KB)
hjie30
(Marcus)
January 5, 2023, 6:46am
15
Thank you very much, it works
1 Like
hjie30
(Marcus)
January 5, 2023, 6:47am
16
Sure thank you, I will take a look.
system
(system)
Closed
January 8, 2023, 6:48am
17
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.