Variable.Contains("hello") don't work

Hi! I have check excel file:
art.Contains(“art”) And model.Contains(“model”) And cost.Contains(“price”) And mass.Contains(“mass”) And sklad.Contains(“wert”) And cell.Contains(“cell”)

Then I have decision, if true - it works. But if false - I have this error:
VisualBasicValue: Object reference not set to an instance of an object.

Hi there @RPA3,
I trust you are having an awesome day!

This error usually occurs when you try to interact with a Variable that is not initialised.

Would it be possible to share the code?
Thanks in advance,
Josh

1 Like

my code

Hi there,
Apologies, I meant the XAML :smiley:

From memory, I believe doing a .Contains on a null String will cause this error, so it may be worth check whether the Variables are null/not populated beforehand:

If String.IsNullOrWhiteSpace(art) Then
Throw - “Variable art is not initialised or not populated.”

Thanks once again,
Josh

@RPA3

Please run the project in Debug mode and check for art, model, cost, mass , and cell.
I believe these are some variables and one of them is null.

I know. I have a condition that if they are 0, then I perform certain actions …
how then to do it right?

So before this Expression , Please check if all the Objects are initialized and are not null as shown below.

Take an IF and Write the below Expression and in the true part mention your Expression
String.IsNullOrEmpty(art) and String.IsNullOrEmpty(model) and String.IsNullOrEmpty(Cost)


Mukesh

hello guys,
i’m facing a similar problem
i’ve string = “row(0).ToString.Contains(”“ABC”")" and i’ve pass this in if condition to evaluate and give me true or flase

do we have equivalent of Eval() or Evaluate() in UiPath.

UiPath needs Boolean as value and not String.

Convert.ToBoolen function fails.

@Pradeep_Shiv It Shuld be just this, row(0).ToString.Contains(“ABC”) in If Condition :sweat_smile:

hello @supermanPunch i’m sending this as a string in if condition

@Pradeep_Shiv If Condition is based on True or False values, so you cannot pass a string :sweat_smile:
It would be better if you show us a Screenshot

BoolCondition = System.Convert.ToBoolean("row(0).ToString = ““ABC”” ")
and BoolCondition i should pass it in If

@Pradeep_Shiv Assuming BoolCondition is of the type Boolean , Try this BoolCondition = System.Convert.ToBoolean(row(0).ToString = “ABC”)

StrVariable = "row(0).ToString = ““ABC”” "
BoolCondition = System.Convert.ToBoolean(StrVariable)
and BoolCondition i should pass it in If

this will work but this is of type “row(0).ToString =”“ABC”" "

BUT I NEED FOR THEY TO BE ZERO

IF THESE WORDS ARE ONE ACTION
and if NO (empty or other is not important), then other actions

Do you know?

Hi @RPA3

There are several ways to approach your scenario

Since your Expression is full of AND, @mukeshkala suggested to do the null checking first before executing yours.

However I think that it should be
NOT ( String.IsNullOrEmpty(art) OR String.IsNullOrEmpty(model) OR String.IsNullOrEmpty(Cost))

If = True, then you perform your Condition

You can combine the null checking to your Expression but will make your Expression very long.
Take note that you should use AndAlso. Some people implements it using Invoke Code.

ex:
(not String.IsNullOrEmpty(art) AndAlso art.ToString.Contains("art")) AND (not String.IsNullOrEmpty(model) AndAlso model.ToString.Contains("model")) AND (not String.IsNullOrEmpty(Cost) AndAlso model.ToString.Contains("Cost"))
etc

Stick to your existing implementation, and just Surround with Try Catch
so that if there is an Exception, you can still perform the False activity in the Catch section.

Hope this helps.

2 Likes