Need help with a for each row trying to match a get text to a DT

I’m having trouble trying to get this to work, what I have is two things, one a get text output “PinNum” in the image you can see I tested it to make sure it was getting the data in a message box. The other is a data table called “dt_veritity” and that logs a message that it is getting the data in the PIN column. I’m positive that I’m either missing something in the for each area or that you can’t compare a string to a data table? If anyone could steer me in the right direction that would be great! I’m new at this so any help could help :slight_smile: The goal is to look for the PIN column number in the excel and compare it to the get text in the application to see if they match. When I run the bot I get the error in the for each area of Object reference not set to an instance of an object. In that second for eac


h ignore that dt_PIN that was my attempt to convert the get text output to a data table but that did not work. So my question is do I have to convert the get text to a data table to compare it or can you compare get text output to a data table column?

Hi @jeff.shubzda,

few things that you need to check:

  1. Looks like dt_Pin doesn’t contain anything. Please check what value and in what scope you have assigned it.
  2. In order to compare your get text value to dt value(that you have printed using log message as well), you just need to write like below under if:
    row.item(“PID”).ToString.Equals(PinNum)

You don’t need to convert get text output to a datatable. Its a string value, can be directly used.

Please try, it should work.

Regards
Sonali

2 Likes

HI @jeff.shubzda,

Please let me know when you have tried this.

Regards
Sonali

I did and it removed the error I was getting, I removed the 2nd for each also however the matching is not happening, I get a message of NOT have a match. I know they match in theory?

Hi @jeff.shubzda,

Glad to hear it resolved the error.

To check whether these values are same or not, please add log message right before if statement to see what value those variables contain at the moment, this would pinpoint whether the values exactly match or not.

Regards
Sonali

1 Like

Very ODD, look down in the logs and I see a match yet I got a NO match message? Hmmm

Hi @jeff.shubzda ,

There might be trailing spaces in either of these variables.

(row.item(“PID”).trim).Equals(PinNum.trim)

Also to verify if there are any spaces, in your log message for both variables, type in like below with no space in between:

“Hello”+PinNum+”there”

“Hello”+Row.item(PID)+”there”

Regards
Sonali

1 Like

Thank you so much for your help. I tried that .trim above but was still not getting a match so I modified the if statement to this - cint(row.item(“PID”).ToString) = PinNum and it gave me a match. I hope that is the solution. Thanks for the help!

Ahh, dint know you had defined PinNum as int type.

Yes that’s the way for matching int types.
You dont need to convert to string first, you can use like below:
CInt(row.item(“PID”)) = PinNum

It should work.

REgards
Sonali

1 Like

Thank you for the help. Now I have to compare two dates to see if they match :slight_smile: that should be fun. My guess is that I have to convert the string to a DateTime format.


Not sure if I’m on the right path with dates. I used a get text to get the date out of the application then used an assign activity of StrDate1 = DateTime.ParseExact(EffDate, “MM-dd-yyyy”,System.Globalization.CultureInfo.InvariantCulture) creating a datetime variable of EffDate.
So now i need to compare the column in the DT (EFF DT) to the new DateTime variable. Am I on the right track?

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