Expression problem

Hello Guys

I used read range the Excel file and saved it as DT,
image

Then I try to use the input dialog to let the user input the ID they want.
image

I want to use if…then activity to tell the user whether can find the id or not in Excel, however, the expression seems incorrect in this case. Anyone can help ? Thanks


@CHAN_Hiu_Fung_Victor_Stud

exists = dt.AsEnumerable().Any(Function(row) row.Field(Of Integer)("Id") = inputId)

Give the Double if it gets the error even giving the Integer as datatype

exists = dt.AsEnumerable().Any(Function(row) row.Field(Of Double)("Id") = inputId)

@CHAN_Hiu_Fung_Victor_Stud ,

If your user input is in different datatype than string then use this:

dt.AsEnumerable().Any(Function(row) row.Field(Of String)(“Id”) = inputId.ToString)

Else use this:
dt.AsEnumerable().Any(Function(row) row.Field(Of [User Input Variable Data Type])(“Id”) = inputId)

Thanks,
Ashok :slight_smile:

Hi @CHAN_Hiu_Fung_Victor_Stud

Try this:
=> Read Range Workbook
image
Output-> dt
=> Input Dialog Box:
image
Output-> ID

=> Use the below syntax in If condition:

If
  dt.AsEnumerable().Any(Function(row) row.Field(Of Double)("ID") = Cdbl(ID))
Then
     Msg Box-> Found
Else
     Msg Box-> Not Found
End If


Regards

1 Like

thanks for your help!

@CHAN_Hiu_Fung_Victor_Stud

If my Solution works for you mark my thread as Solution,Please

1 Like

@CHAN_Hiu_Fung_Victor_Stud

For one post you are able to give one person as solution

Hello @Parvathy

I follow your steps but this error occurs. Do you know why?

Hi @CHAN_Hiu_Fung_Victor_Stud

Try this in If once:

dt.AsEnumerable().Any(Function(row) row.Field(Of String)("ID") = ID)

Regards

1 Like

It works! Thanks so much !!!

1 Like

You’re welcome @CHAN_Hiu_Fung_Victor_Stud

Happy Automation!!

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