Default value is considered blank

Hello !

I’ve met several times this problem. I thought the default value was a great tool to avoid some ‘Assign’ activities but it seems it doesn’t.

My problem is the following:

I have a string variable called A with a default value equals to “First_Name”+“_”+B
B is a string variable aswell. It doesn’t have a default value.
So I’ve set an input dialog activity to assign a string value to variable B. Let’s say B = “Something”.

Since I’ve said that the default value is “First_Name”+“_”+B, I’m expecting that when I’m using the string variable A, its value is “First_Name_Something”.

→ I do not use an assign activity to set A.

Actually, the output of A is First_Name_, ignoring the default value.

And I verified the B value with a write line activity (which has got the correct value I’ve set).
Looks like the default value is not supporting dynamic values but only hardcode.

So my question is : why does the default value of A is not taken into account the B value ?

Thank you very much

Hi @LamaX

Can you share the workflow for better understanding?

Regards

Lets assume the following
grafik

Variable definition and orders (similar to your input change case)

And a first Dump / Inspection
grafik

We can see that a change on B is not doing change on A. Similar as we had understood your problem description.

We do feel that the Assignment in VarA DefaultValue is using B byValue (at the assignment it is empty) and not byReference

therefore A stays FirstName_ and is not turning to FirstName_HelloWorld

Kindly note: there are datatype (often complex datatypes. e.g. DataTable) where Assignments are setting in a way of ByRef

1 Like

Thank you for your feedback !

Of course ! Here it is :
TestUiPathForum.zip (39.6 KB)
Let me know if it’s not working. I just zipped the folder as it is.

@ppr : I’m not sure to fully understand what 's the difference of using a variable “byreference” and “byvalue”.

Is there a workaround in this case ? Should I set something in the parameters ?
And what is the point of default value if it’s not possible to link variables togheter ?
Is it just for hardcoding ?

Hi @LamaX


In the above image the A is initialized with a default value. So when the code executes then It reads the variables and arguments first and then the code gets to execute. So in your scenario the B is initialized will null value so that’s why the B value printing as empty in “First_Name”+B. The input dialogue box is later so that’s why the B value is not getting printed in the First log message.

So if you want to print the B value in first log message then you need to assign a default value for B also as shown below and also the Value B should be kept above the Value A

In input dialogue box I have given the B value as Bye and here is the log messages output.

TestUiPathForum.zip (144.1 KB)

Regards

1 Like

So when the code executes then It reads the variables and arguments first and then the code gets to execute.

Ok, I understand. So somehow default values are used just for hardcoding (default) values ?

Thank you very much !

We assume that you are exploring concepts of development and VB.Net

In short: ByRef - Visual Basic | Microsoft Learn

we mentioned:

so it depends on a few factors if an assignment will use the value by copy (ByVal) or will use the reference to the variable (ByRef)

no, as mentioned above and we often use e.g. for initializations of e.g. Lists, DataTables…

1 Like

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