Count length string

Hello,

I want to count length in column Create ID by use if condition

If CurrentRow(“Create ID”).Tostring.Length<7

remark

But error : Object reference not set to an instance of an object.

I debug run output as below.

image

Please guide me for solve it.

Hi @fairymemay

Do you have empty cells in Create ID column?

Regards

@Parvathy yes, some row empty cell

@fairymemay,

When the value of the column will be null or empty it will throw this error.

Try checking if it’s null first.

CurrentRow(“Create ID”) IsNot Nothing AndAlso Current Row(“Create ID”).Tostring.Length<7

Thanks,
Ashok :slightly_smiling_face:

Hi @fairymemay

Try the below condition in If then:

If
 Not String.IsNullOrEmpty(CurrentRow("Create ID").ToString()) AndAlso CurrentRow("Create ID").ToString().Length < 7
Then
   ' Add your logic here (e.g., set a remark or update a column)
End If

Hope it helps!!

Hi,

If you want to handle empty (null) as 0 length, the following will help you.

Current Row("Create ID") is Nothing OrElse Current Row("Create ID").Tostring.Length<7

Regards,

Now error as below.

image

Please put Current Row(“Create ID”) is Nothing first, then connect with OrElse

@Yoichi Same error as below.
I have 3 condition in if condition

image

Hi @fairymemay

Check whether Create ID column name has any trailing spaces at the End,and try the below condition:

If
 Not String.IsNullOrEmpty(CurrentRow("Create ID").ToString()) AndAlso CurrentRow("Create ID").ToString().Length < 7 AndAlso CurrentRow("Create ID").ToString.Equals("ESPGADMIN")
Then
   ' Add your logic here (e.g., set a remark or update a column)
End If

Regards

@Parvathy why use andalso in 3 condition ?
If morethan 1 condition I want go to then.

Please guide me for solve it.
Thank you.

Hi @fairymemay

Do you want the condition to go to then even if one of the conditions satisfy. Please specify.

Regards

@Parvathy I have 3 condition

  • blank
  • length <7
  • text = espgadmin

but If true condition (some or all condition) go to then

image

Hi @fairymemay

Can you share your excel file with all conditions. I will help you with flow.

Regards

@Parvathy Example file as attached.

input.xlsx (8.0 KB)

1 Like

Give me some time. I will help you with flow @fairymemay

Regards

1 Like

@fairymemay

Your requirement is to delete the row according to the three conditions.

Regards

@Parvathy Yes delete row in excel input that match condition.

@fairymemay

String.IsNullOrWhiteSpace(row("Create ID").ToString) OrElse row("Create ID").ToString.Length < 7 OrElse row("Create ID").ToString.Equals("espgadmin", StringComparison.OrdinalIgnoreCase)

Hope this works for you

1 Like

@fairymemay

=> Read Range Workbook
image
Output → dt

=> Use below syntax in Assign:

FilteredDt = (From row In dt.AsEnumerable()
              Let createId = row.Field(Of Object)("Create ID").ToString()
              Where Not (String.IsNullOrEmpty(createId) OrElse
                    (IsNumeric(createId) AndAlso createId.Length < 7) OrElse
                    createId.ToUpper() = "ESPGAMIN")
              Select row).CopyToDataTable()

FilteredDt is of DataType System.Data.DataTable

=> Write Range Workbook
image

Hope it helps!!

1 Like