How to store variable value into array?

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?

image

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)

@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

  1. If you need to get the value in int, set price list variable as a Array of integer.
  2. While concat, use cint(Stringvariable)
PriceList.Concat({cint(Price)}).ToArray
  1. 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)

  1. If you need to get the value in double, set the price list variable as an Array of Double.
  2. 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.

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
image

sample.Append(Cdbl("22.35")).ToArray

image

Regards
Sudharsan

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
image

@hjie30

Try removing the double curly braces {} and try again?

Regards
Sudharsan

image

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)

Thank you very much, it works

1 Like

Sure thank you, I will take a look.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.